Help with grouping data based on range position

Input file:

data_1 1000 1290
data_4 290 234
data_2 1114 1110
data_5 534 999
data_6 900 1050
.
.

Desired_output_file_1_0_999:

data_4 290 234
data_5 534 999

Desired_output_file_2_1000_1999:

data_1 1000 1290
data_2 1114 1110

Group all those content which range from 0-999 to file_1_0_999, 1000-1999 to file_2_1000_1999, etc
If the read are range between two desired output file (eg. "data_6 900 1050" are range within 0_999 and 1000_1999) are discarded.
Thanks for any script or command to solve my doubts.

#!/usr/bin/perl -an
if (int($F[1]/1000)*1000==int($F[2]/1000)*1000){
  $o="Desired_output_file_" . (int($F[1]/1000)+1) . "_" . int($F[1]/1000) . "_" . (int($F[1]/1000)*1000+999);
  open O, ">>$o";
  print O;
  close O;
}

Run it as: ./script.pl file

1 Like