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

my $str = "Hello\n\t\n World\n"; print $str; $str =~ s/\s+/ /g; print $str;

Output

Hello World Hello World

Update: Please note this replaces all whitespace chars to a single space char. So if you have leading/trailing spaces please go with Your Mother's solution!