use Path::Class; my $dir = dir('foo'); $dir->recurse(callback => sub { unlink $_[0] if !$_[0]->is_dir; }); $dir->rmtree(0, 1);