fork download
  1. my $str = " word1 word2\n word3 word4 word5\n";
  2. print "str before = $str\n";
  3. $str =~ s/(?<!^)(?<![ ])[ ]+/ /mg;
  4. print "str after = $str\n";
Success #stdin #stdout 0s 4552KB
stdin
Standard input is empty
stdout
str before =          word1     word2
     word3     word4     word5

str after  =          word1 word2
     word3 word4 word5