foreach $n(@array) { if (opendir DIRHANDLE, $n) { do something with DIRHANDLE; } }