foreach (1,2,3,4) { print "dir1\n" if glob("dir1/f*"); print "dir2\n" if glob("dir2/f*"); }