in reply to sed deleting file

Calling out to sed from perl is pretty carrying-coal-to-Newcastle. Just open the old file, open the output, loop over the old lines using the same substitution, and print to the output file.

The cake is a lie.
The cake is a lie.
The cake is a lie.