for my $path (...) { # Or a while opendir my $dir => $path or do { warn ...; next; } ... something with $dir ... }