# Look closely: sort { $a=>rank <=> $b->rank } @$messages # Your sort sub is returning (I think): ($a, (rank <=> $b->rank))