in reply to Retain file format

The browser doesn't care whether there are newlines in the html or not. It takes its formatting from the html markup. To preserve the format of the rewritten file, don't do $text =~ s/\n/ /g;.

After Compline,
Zaxo