grouping lines and concatenating them into one line in perl

This seems like a basic thing to do, but I can't figure out a simple way doing it without starting building lots of arrays etc. so my apologies if this is too simple.

I have a file of this format:

a,x1
a,x2
a,x3
b,x4
c,x5
c,x6

this is an edge list for a very big graph.
I need to convert it to the following format:

a,x1 x2 x3
b,x4
c,x5 x6

(this is another common format of graphs)

Is there a simple way of doing that in perl? you can assume that all the "a" and "b" are sorted, so once you got to a new starting node (say "b") there will be no going back (e.g. no more edges outgoing from "a")