# Open both IN_FILE and OUT_FILE here! while() { chomp; next unless length; print OUT_FILE "$_\n"; } #### open (INFILE, "input.txt"); open (OUTFILE, ">output.txt"); while (INFILE) { $_ =~ s/foo/bar/gms; print OUTFILE "$_\n"; }