Using Perl to Merge Multiple Lines in a File

I've hunted and hunted but nothing seems to apply to what I need. Any help will be much appreciated!

My input file looks like (Unix):
marker,allele1,allele2
RS1002244,1,1
RS1002244,1,3
RS1002244,3,3
RS1003719,2,2
RS1003719,2,4
RS1003719,4,4

Most markers are listed 3 times but a few have 3 alleles and are listed more.

An example of a marker with 3 alleles is:
marker,allele1,allele2
RS757210,2,2
RS757210,2,3
RS757210,2,4
RS757210,3,3
RS757210,3,4
RS757210,4,4

I would like to get output like:
marker,allele1,allele2,allele3
RS1002244,1,3,.
RS1003719,2,4,,
RS757210,2,3,4

Thanks very much in advance, Peggy 10/23 (happy to have this in formats other than Perl, too)

Not sure about your requirements, but this awk may help:

NR == 1 { print "marker,allele1,allele2,allele3" }
NR > 1 {
  if ($1 != lm) {
    if (lm != "") print substr(",,,", 1, 3-c)
    printf("%s,%s", $1, $2)
    c = 1
    split("", seen)
    seen[$2]
    lm = $1
  }
  if (!($2 in seen)) { printf(",%s", $2); ++c; seen[$2] }
  #if (!($3 in seen)) { printf(",%s", $3); ++c; seen[$3] }
}
END { print substr(",,,", 1, 3-c) }

Thanks very much! Very close and give me new stuff to learn and play with.