in reply to formatting newline characters

Perl is smart about \n and the value of it changes to whatever is used for the line-ending on your operating system.

There is no need to use an if-then, just try the substitution and if there is nothing to substitute then it wont substitute.

But more than likely you can just chomp $input.