use strict; use warnings; my %month_sort = ( 'JAN' => 1, 'FEB' => 2, 'MAR' => 3, 'APR' => 4, 'MAY' => 5, 'JUN' => 6, 'JUL' => 7, 'AUG' => 8, 'SEP' => 9, 'OCT' => 10, 'NOV' => 11, 'DEC' => 12 ); sub sort_cmp { ( substr($a, 3, 2) cmp substr($b, 3, 2) ) || ( $month_sort{substr($a, 0, 3)} <=> $month_sort{substr($b, 0, 3)} ); } my (@months) = qw(APR12 MAR13 APR11 MAR12 FEB13 APR13); @months = ( sort sort_cmp @months); print "@months \n";