use warnings; use strict; my @firsts; my @seconds; while() { chomp; my($val1,$val2) = split /,/; push @firsts, $val1; push @seconds, $val2; } @firsts = sort {$a <=> $b} @firsts; @seconds = sort {$a <=> $b} @seconds; my @sorted; push @sorted, [$firsts[$_], $seconds[$_]] for 0..$#firsts; print "$_->[0], $_->[1]\n" for @sorted; __DATA__ 10,20 30,10 20,70 70,80 40,90 90,100 50,50 #### 10, 10 20, 20 30, 50 40, 70 50, 80 70, 90 90, 100