You're on the right track. After this: $lines =~ s/foo/bar/gms;the substitution has been made, but it's still in memory. The next step is to write it to the file:
You said "other file", so I'm not sure if you want to overwrite the original file or not. If you do, just substitute its name instead of theother.txt above.open(FILE, ">theother.txt") or die "Can't open the other file: $!\n"; print FILE $lines; close FILE;
HTH
In reply to Re: Regex to find/replace in a file
by VSarkiss
in thread Regex to find/replace in a file
by amarceluk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |