Given the format of file you are reading, Config::IniFiles might do a better job at giving you the key / value pairs that you can then dump in another file. It can handle multi-line values that your simple replace breaks, see Parameter Files in the Oracle DB ref