use strict; use warnings; my %find; open INDEX, '<', shift( @ARGV ) or die $!; while( ) { @find{ $_ .. $_ + 2 } = (); } close INDEX; while( <> ) { next unless exists $find{$.}; print $_; delete $find{$.}; last unless keys %find; }