in reply to Need help with efficient processing

Why reopen the directory again to look for files matching $1-$2-$3? You are going to see those filenames eventually. Just populate the hash as you go, and let things fall into place. Use a 2nd layer of hashing with the date as the key, then you can sort on the date later as you need. You may want to consider doing a deep hash, with each part of the filename acting as a key at some level. You can still get sorted retrievals given the first 3 components as a key.
my %files; foreach (readdir(MYDIR)) { if (/([^-]+)-([^-]+)-([^-]+)-([^-]+)\.(pdf|html)/) { # using temp variables for illustrative purposes my ($name, $country, $language, $date) = ($1, $2, $3, $4); $files{$name}{$country}{$langauge}{$date} = $_; # alternatively for a less nested hash, you could do # $files{ join '-', $name, $country, $language }{$date} = $_; } } #### later sub get_files_by_key { my ($name, $country, $language) = @_; my $hash_ref = $files{$name}{$country}{$language}; # alternatively # my $hash_ref = $files{ join '-', $name, $country, $language }; # in any case, sorting them here is easy return map { $hash_ref->{$_} } sort keys %$hash_ref; } my @relevant_files = get_files_by_key('foo', 'us', 'en');
Obviously after reading this tale, you'll know that I'm unworthy to receive your assistance, but I beg to receive it.
Hey, this isn't the Internet Oracle. No need to supplicate!

ZOT,

blokhead