#!perl use strict; use warnings; my $file = "test.txt"; open (IN, $file) || die "$file not found\n"; my @bigram = ; close (IN); chomp @bigram; my %count; my $word; foreach my $sequence (@bigram) { my $count; my @word = split ' ', $sequence; foreach $word(@word) { $count{$word}++; } } foreach $word (sort by_count keys %count) { print "$word occurs $count{$word} times\n"; } #orders the count sub by_count { $count{$b} <=> $count{$a}; }