The Perl version works the way you expected.
perl -i -p -e 's/\n//' file perl -i -p -e 's/\n//' file As pointed out in the comments, it's worth noting that this edits in place. -i.bak will give you a backup of the original file before the replacement in case your regular expression isn't as smart as you thought.