in reply to Re^2: using s///g;
in thread using s///g;

Nope, you essentially can't change a free-format sequential file like that. That's why, behind the scene, you have to rename your original file (say into file.old), and then write your changed content to a new file having the name of your original file.

The alternative is to read the whole file into memory, make the changes in memory and then clobber the content of the original file and write the new content to it.