in reply to reg perl substitution

You read lines from a file into a variable, and then change that variable - you don't change the file.

There are several options, perhaps the easiest is to write to a temporary file first, and then move this to the location of the old file.

Or you could use Tie::File - that changes the file that it's tied to.