Is there a built-in function to trim leading and trailing whitespace such that trim(\" hello world \") eq \"hello world\"?
trim(\" hello world \") eq \"hello world\"
Apply: s/^\s*//; s/\s+$//; to it. Or use s/^\s+|\s+$//g if you want to be fancy.
s/^\s*//; s/\s+$//;
s/^\s+|\s+$//g