my $sentence = 'This is a test'; my %hash = map { $_, 1 } ($sentence =~ /\w+/g); #### my $sentence = 'This is a test'; my %hash; for ($sentence =~ /\w+/g) { $hash{ $_ }++; }