in reply to Trimming Paths with regexes

Returns the path shortened and handles paths with //'s together like ////usr/bin correctly. Returns undef in the special case of the root path. Does not handle relative paths

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