in reply to regexp problem

($str) = ($str =~ /^\s*(.*?)\s*\z/) or just
$str =~ s/^\s+//; $str =~ s/\s+\z//;