$str =~ s/((^|\s)\s*)/length ($2) ? (-1 < index ($1, "\n") ? "\n" : ' ') : ''/ges;