in reply to problem with foreach
EDIT: I'm to slow - see node above
You can fill the array in one step using qw, and you can count all 'b' in this array in one step using grep:
my @ar = qw /a b b a/; my $cnt = 0 ; $cnt = grep /b/, @ar;
In Section
Seekers of Perl Wisdom