use Sort::Key::Multi 'iiikeysort'; # the 'iii' stands for three integer keys my (%month, $month); $month{$_} = ++$month for qw(jan feb mar apr ...); @sorted = iiikeysort { /^webadmin_(\w+)_(\d+)_(\d+)\.log$/; ($3, $month{$1}, $2) } @filenames;