Help for this page
s/\s*$/\n/s; # assuming \s will catch your newline s/\s*[\r\n]+$/\n/; # otherwise, this should do it
substr($_, -2, 2) = undef; # deletes last 2 characters substr($_, -3, 3) = "\n"; # if your string ends in a newline