in reply to regex verses join/split

As long as you want to squeeze whitespace, do that first, and the regex engine might optimize the leading/trailing substitution, so then here's another possibility to benchmark:
# Squeeze whitespace tr/\n\r\f\t //s # Then # This: s/^\s|\s$//g; # Or this: s/^\s//; s/\s$//;