Search, group , print count

hi All,
need help. have a file like below
A, error in 123
B, log files are present
A, error in 23444
B, log files are present
A, move to next line
C, matching messages

-- expected output--

A , count =2 , error in *
A , count =1 , move to next line
B , count =2 , log files are present
C , count =1 , matching messages

if pattern is always same, sort | uniq -c will help ..
but when patterns differ for few words - want to pick matching content and ignore unmatched , want a count on them.. not getting a clue on how to start/ where to start

#!/usr/bin/perl
open I, "$ARGV[0]";
while (<I>){
  chomp;
  /^(\w+, \w+)/;
  $m=$1;
  if (!$l{$m}){
    $c{$m}++;
    $l{$m}=$_;
  }else{
    $c{$m}++;
    @x=split //;
    @y=split //, $l{$m};
    $l{$m}="";
    for ($i=0;$i<=$#y;$i++){
      if ($y[$i] eq $x[$i]){
        $l{$m}.=$y[$i];
      }else{
        $l{$m}.="*";
        last;
      }
    }
  }
}
for (keys %c){
  $l{$_}=~s/^(\w+)//;
  print "$1 , count =$c{$_} $l{$_}\n";
}

Run this script as: ./script.pl file

Maybe this will be enough?

% sort INPUTFILE | uniq -c -w 10
      2 A, error in 123
      1 A, move to next line
      2 B, log files are present
      1 C, matching messages

If you need more specific output, you can make it with awk or perl.