open OUTFILE, "<$outfile"; open FINAL, ">$final"; while () { print FINAL if /(line1)/; print FINAL if /(line2)/; print FINAL if /(line3)/; }