open INFILE, "$inputfn" || die "Error reading input file: $!\n"; open OUTFILE, ">$outputfn" || die "Error opening output file: $!\n"; while () { ##...a bunch of stuff munged with regexes omitted... print OUTFILE "$_\n"; } close OUTFILE; close INFILE;