my @sorted = sort by_year_and_month @files; sub by_year_and_month { year($a) <=> year($b) or month($a) <=>month($b); } sub month { substr shift, 0, 2; #used to say '0, 1' but chipmunk caught the mistake } sub year substr shift, 2, 2; #used to be 2, 3 but see above! }