perl : Read filenames from a Directory

Perl provides built in glob function which can be used to read the list of files in a directory.

@files = </path/to/search/pattern_to_search>;

Here is working code example that prints all filenames from current directory, one per line. The glob happens when the <> characters pulls the filenames into the @files array.

#!/usr/bin/perl
@files = <*>;
foreach $file (@files) {
        print "$filen";
}

So if you were to find all php files in your webserver directory use

@files = </var/www/htdocs/*.php>