in reply to Working with a unkown number of arrays

Files of lower priority are unprocessed, so the finding can be cut short when files are found in a higher folder.e.g.
my @folders = glob 'input_directory*'; # get/sort all qualifying folde +rs my @requests; for (my ($found, %filedate); $found = pop @folders or exit();) { @requests = sort { { ( $filedate{ $a } ||= -M $a ) <=> ( $filedate{ $b } ||= -M $b ) } glob "$found/" . 'Flat_file.*.txt' and last; # reiterate iff none found }
If the loop completes having found @requests, they will have been selected from the highest non-empty qualifying directory and be sorted by creation/modification date. (updated)

-M

Free your mind