use File::Spec::Functions qw( splitpath splitdir catpath catdir ); sub unmkpath { my ( $path ) = @_; my ( $vol, @dir ) = do { my ( $vol, $dirs ) = splitpath( $path, 1 ); ( $vol, splitdir $dirs ); }; pop @dir while @dir and rmdir catpath $vol, catdir( @dir ), ''; }