in reply to printing specific lines

If the text file could be large, consider
open (IN, "<grep"); my %lines; while (<IN>){ $lines{$_} = 1; } close IN; open (OUT, ">gout"); # assumes input data comes from stdin while (<>){ print OUT $_ if exists $lines{$.}; } close OUT;
Untested, but I think I got it right. Save the small stuff, not the big stuff.