IMO trim should operate in place in void context and return the substring in nonvoid context. Optimizing >> $string = trim($string); > Into ; trim($string); is clearer but unnecessary. $string =~ s/\s*(.*?)\s*$/$1/; >