sub pathtrim { my ($path) = @_; return '/' if ($path =~ m#^/[^/]+$/); $path =~ s#/[^/]+$##; return $path; }