my @files = map { $_->[2] } sort { $b->[0] <=> $a->[0] or $b->[1] cmp $a->[1] } map { [-d "$dir/$_" || 0, lc $_, $_] } readdir $dh;