- or download this
s/^\s+//;
s{ [^\S\n]* (?: (\n)\s* | [^\S\n]+ ) }{ $1 || ' ' }gex
- or download this
s{(?<=(\S))?\s+(?=(\S))?}{length($1.$2)?'':' '}gx
- or download this
s{(?<=(\S))?\s+(?=(\S?))}{length(($1//'').$2)?'':' '}gx
- or download this
s{(^)?\s+(\z)?}{$1//$2//' '}gx