in reply to Replace strings in text file

What are you trying to accomplish here? Have you read man page of sed ?

The sed utility is a stream editor that reads one or more text files, makes editing changes according to a script of editing commands, and writes the results to standard output.

Since you are already using perl, why not just use perl to perform substitution (a lot of monks had already given out code) instead of *nix sed, then your code will be portable (across other OSes, like windows).