open OUTFILE, "<$outfile"; open FINAL, ">$final"; while () { print FINAL if /(my first line)/; print FINAL if /(my second line)/; print FINAL if /(my third line)/; #### line1
line2
line3
##
## line 1 line 2 line 3 #### line1
line2
line3