use strict; use warnings; use File::Slurp; use File::Path qw( remove_tree ); use Cwd; my $dir = shift; #path/to/cache my @dirs = read_dir( $dir ); my $path = getcwd( $dir ); for (@dirs) { next if ( -f $_ ); if ( $_ !~ /(?:_)/ ) { my $removed = $path . "$dir/$_"; remove_tree($removed); print "removed : $removed\n"; } }