use File::Find qw(finddepth); finddepth sub { -d and rmdir $_ and printf STDERR "rmdir: %s\n", $File::Find::name }, @dirs;