I could find the last modified file in a directory as below.


my $directory = '/home/userrig/testing/';
opendir(DIR2, $directory) or die "Can't open $directory: $!";
@files = grep {/\.txt$/i} readdir(DIR2); #get txt files only
@sorted = sort {-M "$directory$a" <=> -M "$directory$b"} @files; #sort them by modification date most recent to least recent
print "The most recent modified file is: $sorted[0]";
How do I modify so that I can get the last modified directory under /home/userrig/testing/', the directories starting with test...