use File::Path; use File::Spec::Functions qw( splitdir catdir ); sub rmtree_path { my ( $path ) = @_; rmtree $path; my @path = splitdir $path; do { pop @path } while @path and rmdir catdir @path; }