my @dat_; foreach (@data) { if (m/Sec\_$i/ .. m/Sec\_$j/) { push @dat_, $_; } }