my $dir = '/genomes/Bacteria'; # use single quotes where possible, e.g., no var or \n # it's a tiny bit faster ## get the contents of a directory my @dir_listing = <$dir/*>; ## note: using <$dir/*/> would find all the directories ## removes . and .. while ($dir_listing[0] =~ /^\.+$/) { shift @{$dir_listing}; } ## removes all directories my @files_found = map { (-d $_) ? () : $_ } @dir_listing;