# the initial array my @AOH=( {dayOfMonth=>19, clockReading=>02}, {dayOfMonth=>21, clockReading=>12}, {dayOfMonth=>15, clockReading=>04}, {dayOfMonth=>19, clockReading=>05}, {dayOfMonth=>15, clockReading=>23}, {dayOfMonth=>19, clockReading=>12} ); # here's where you specify the ordering for the days of the # month... my %dayOfMonthMap=( 21 => 1, 17 => 2, 14 => 3, 15 => 4, #... 19 => 21, # let's say ); # For speed, let's remap that to an array, with the index # being the day of the month my @dayOfMonthRemap; foreach(keys %dayOfMonthMap) { $dayOfMonthRemap[$_]=$dayOfMonthMap{$_}; } #ok, now we're ready to sort! my @sortedArray=sort { # if it's the same day, the || will make # this compare by clockReading $dayOfMonthRemap[$a->{dayOfMonth}] <=> $dayOfMonthRemap[$b->{dayOfMonth}] || $a->{clockReading} <=> $b->{clockReading} } @AOH; # Let's print out the result to make sure it's sane... foreach(@sortedArray) { print "$_->{dayOfMonth} : $_->{clockReading}\n"; }