sub trim { @_ = $_ if not @_ and defined wantarray; @_ = @_ if defined wantarray; for (@_ ? @_ : $_) { s/^\s+//, s/\s+$// } return wantarray ? @_ : $_[0] if defined wantarray; } trim; # trims $_ inplace $new = trim; # trims (and returns) a copy of $_ trim $str; # trims $str inplace $new = trim $str; # trims (and returns) a copy of $str trim @list; # trims @list inplace @new = trim @list; # trims (and returns) a copy of @list