my $str = " word1 word2\n word3 word4 word5\n";
print "str before = $str\n"; $str =~ s/(?<!^)(?<![ ])[ ]+/ /mg;
print "str after = $str\n";
bXkgJHN0ciA9ICIgICAgICAgICB3b3JkMSAgICAgd29yZDJcbiAgICAgd29yZDMgICAgIHdvcmQ0ICAgICB3b3JkNVxuIjsKcHJpbnQgInN0ciBiZWZvcmUgPSAkc3RyXG4iOwokc3RyID1+IHMvKD88IV4pKD88IVsgXSlbIF0rLyAvbWc7CnByaW50ICJzdHIgYWZ0ZXIgID0gJHN0clxuIjs=