use strict; my $wildcard = $ARGV[0]; print "wildcard is $wildcard\n"; my $filespath = '/path/to/files/'; opendir DIR, $filespath or die "Couldn't open $filespath: $!\n"; # Sort by asc order (time) # (The commented line below sorts all the files that end with ".cgi" #my @dirfiles = sort { -M $filespath.$a <=> -M $filespath.$b } grep /\.cgi$/, readdir DIR; my @dirfiles = sort { -M $filespath.$a <=> -M $filespath.$b } grep /$wildcard/, readdir DIR; foreach (@dirfiles){ print "$filespath$_\n" }