Software >> Development >> Languages >> Perl >> How to list a directory and filter specific file patters

Example to list only files matching totalpages_????_??_CITS.txt from the current directory. $dirname = "."; print $dirname . "\n"; opendir(DIR,$dirname); @totalpagesfiles = grep{/totalpages_\d{4}_\d{2}_CITS.txt/gi} readdir(DIR); closedir(DIR); foreach $tpf (@totalpagesfiles) { print "$tpf\n"; }