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; } #### perl -ne "BEGIN{open I, '<', shift(@ARGV); while(){ @find{$_ .. $_+2}=();}} next unless exists $find{$.}; print; delete $find{$.} last unless keys %find;"