my $phrase = 'There once was a doggy in the window. I went into the store and inquired about the price, the doggy was too nice to ever think twice, so now I have a doggy to care for.'; my %vowels; while ($phrase =~ /([aeiou])/gi) { $vowels{lc $1}++; } use YAML; print Dump \%vowels; __END__ the output would look like --- a: 8 e: 17 i: 11 o: 15 u: 2