my %result; while (<>) { chomp; my ($k, $v) = split /,/; push @{$result{$k}}, $v; } for (sort keys %result) { print join(",", $_, @{$result{$_}}), "\n"; }