@sorted_refs = map { $_->[2] } sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } map { [ int($_->{SP}/100)*100, DateToTmStr($_->{SaleDate}), $_] } @unsorted_refs;