# create a filehandle to the directory - check for errors opendir (DIR, "path/to/directory") or die "Unable to open directory: $!"; # read in all file names except . and .. @files = grep {$_ ne "." && $_ ne ".."} readdir (DIR); # close the filehandle to the directory closedir (DIR); # do whatever you want with filenames in @files