in reply to How to open file in Edit mode

I would recommend using two files (yourcode.pl file.orig > file.new, for example).

Unless you have fixed size records or $replace_string is smaller than what was matched, you are going to want to use two files or read the entire file into memory. If your replacement string is larger than your match, you will end up overwriting future portions of your file when you write the modified record back to your original file.

As an example, if your replacement string is foobar, and your data file looks like:

sdpRowId:blah sdpRowId:bar
assuming that you have the file read/write code correct (it is not at this point in time), after the first pass, you would end up with something along the lines of:
sdpRowId: foobar RowId:bar
Note that the string 'sdp' at the beginning of the second line was overwritten.

If you do insist on not using two files (or loading the entire data set into memory and rewriting the original file), you will probably need to find out about seek and tell.

Update: Included an example

--MidLifeXis