use warnings; use strict; use Test::More tests=>1; my $str = "iowq john stepy andy anne alic bert stepy anne bert andy step alic andy"; my %names; pos($str)=undef; while ($str=~/\G\s*(\S+)(?:\s+|\z)/gc) { $names{$1}++; } die "failed to parse \$str" unless pos($str)==length($str); is_deeply \%names, { alic => 2, andy => 3, anne => 2, bert => 2, iowq => 1, john => 1, step => 1, stepy => 2 };