If you want to change the file directly, the proper technique is to:
- open a Read/Write filehandle to the file
- read the file into a scalar
- use a supplied regex to modify it
- print the scalar to the filehandle
The node
How do I write to a file? in tue Q&A section on
files may be of assistance.