var s =" \t\v\r\n\ffoo bar \t\v\r\n\f"say s.strip_beg.dump # remove leading whitespacessay s.strip_end.dump # remove trailing whitespacessay s.strip.dump # remove both leading and trailing whitespace
Output:
"foo bar \t\13\r\n\f"
" \t\13\r\n\ffoo bar"
"foo bar"