On a trivial note about counting occurances of letters you can do it all of these ways:
my $txt = "1,2,3,4,5,6";
my $n1 = scalar(split(/,/,$txt))-1;
my $n2 = scalar(@{[ split(/,/,$txt) ]})-1;
my $n3 = scalar($#{[ split(/,/,$txt) ]})-1;
my $n4 = (y/,/,/);
my $n5 = (m/,/g);