. . local $_; # always a good habit unless you know why don't want it chdir $Dir; opendir DIR, '.'; my (@dirs, @files); for (readdir DIR) { next if /^\.\.?$/; # we don't want to catch the . and .. entries push @dirs, $_ if -d and not -l; # only non-symlink dirs please push @files, $_ if -f and /\.ext$/; # -f because it could be a directory or other non-file called "something.$ext" } closedir DIR; . .