Perl makes this so simple it's almost silly.
Code:
sub count_y
{
$string = "Johnny Boy";
$count = ($string =~ tr/y/y/);
return $count;
}
This essentially just replaces every 'y' character with another 'y' character, and returns the total number of replacements to $count. Perl is beautiful.