use strict; use Data::Dumper; my $candidate = 'the the the the the the the'; my @candidate_words = split (/\W/, $candidate); my $candidate_count=@candidate_words; my %candidate = (); map { $candidate{$_}++ } @candidate_words; my $reference = 'the cat is the on the mat'; my @reference_words = split (/\W/, $reference); my %reference = (); map { $reference{$_}++ } @reference_words; while((my $key, my $val)=each(%candidate)){ print $key."->".$val."\n"; } print "-------------------------------------\n"; while((my $key, my $val)=each(%reference)){ print $key."->".$val."\n"; }