use strict; use warnings; use Path::Iterator::Rule; use MCE; my $rule = Path::Iterator::Rule->new; # Add constraints to the rule here my $root = '/some/path'; my $iter = $rule->iter($root, { depthfirst => 1 }); my @list; while ( my $file = $iter->() ) { push @list, $file; } my $chunk_size = 100; # whatever makes sense for you MCE->new( user_func => \&task, max_workers => 10, chunk_size => $chunk_size ); MCE->process( \@list ); MCE->shutdown; exit 0; sub task { my $mce = shift; # not used in this case my $file = shift; unlink($file) if -f $file; rmdir($file) if -d $file; } __END__