@out1 = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { my @d = split /,/; [ join('\0', @d[7,8,0]), $_ ] } @data;