@sorted_pairs = sort { my@a1 = split',',$a; my@b1 = split',',$b; $a1[0] <=> $b1[0] || $a1[1] <=> $b1[1] } @pairs;