use strict; use warnings; my %wordData; my $previousWord; while () { chomp; my @parts = split; for my $part (@parts) { my ($word, $punct) = (lc $part) =~ /(\w+)(.*)/; if ($word) { $wordData{$previousWord}{$word}++ if $previousWord; $wordData{$word}{'!count'}++; } if ($word) { $previousWord = $word; } elsif ($punct) { $previousWord = undef; } } } for my $word (sort keys %wordData) { next if $wordData{$word}{'!count'} < 2; for my $secWord (sort keys %{$wordData{$word}}) { next if $secWord eq '!count'; printf "'%s' is followed by '%s' %.0f%% of the time\n", $word, $secWord, 100.0 * $wordData{$word}{$secWord} / $wordData{$word}{'!count'}; } } __DATA__ Thank you all for the answers... all above for the answering. I am trying something on bigram techniques. where i have stored bigram count in one hash and word count in other. What i am trying to do is: From looping those hashes at once, I want to take the value of bigram count and divide with the value of word count. In case of ordering i used Tie::IxHash module from CPAN. Any better solution to the way i approached my work will be appreciated... Thanks.