opendir THEDIR, "$basepath$ARGV[0]" or die "Unable to open directory: $!"; my @allfiles = readdir THEDIR; closedir THEDIR; for my $file ( sort { $b <=> $a } @allfiles ) { ..... }