in reply to How to remove \n between two words but retain one space

To retain external white space while collapsing internal white space:

use strict; use warnings; my $str = " Hello\n\t\n World \n"; print ">$str<\n"; $str =~ s/\b\s+\b/ /g; print ">$str<\n";

Prints:

> Hello World < > Hello World <

DWIM is Perl's answer to Gödel