my @sorted = sort { $a->[0] cmp $b->[0] || $a->[2] <=> $b->[2] } @$outputRef;