$lines =~ s/foo/bar/gms; #### open(FILE, ">theother.txt") or die "Can't open the other file: $!\n"; print FILE $lines; close FILE;