$input =~ s/\r\n?/

\n/gs ; # after this is just the normal process for HTML (current process).