in reply to problem with foreach
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; [download]