my @info = (); while (my $entry = $dir->next) { if (-d $entry && $entry=~ m/qt_4/) { my $stat = $entry->stat or warn("$entry: $!\n"), next; push @info, $stat->mtime; } } my @newdir = sort{$b<=>$a}(@info); print "$newdir[0]\n";