foreach $n (grep { -d } @array) { ## do stuff }