# It would probably be better have # while (my $line = ) # but that would mean rethinking your whole code for my $line (@SNP) { my $position = (split " ", $line)[3]; last unless $position <= $end; print OUT $line if $position > $start; }