in reply to formatting newline characters
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.