For my cryptography hobby (old school cryptograms, not modern cypto), I wrote this to find frequencies of letter pairs. I don't know if it could be adapted.
#
#
# my $input = shift;
# my $input = "peon bookkeeper";
my $input;
#print $input."\n";
while (<>) {
$input = $_;
@evenmatches = ($input =~ m/
(.{2}?)
(?{ #print $^N . " found at " . ($tmpp
+os = pos($input)) . "\n";
$chars{$^N}++;
})
/xg);
#print join(", ", @evenmatches)."\n";
#print $#evenmatches + 1 ." matches found\n";
#print $input."\n";
pos($input) = 1;
@oddmatches = ($input =~ m/
(.{2}?)
(?{ #print $^N . " found at " . ($tmpp
+os = pos($input)) . "\n";
$chars{$^N}++;
})
/xg);
#print join(", ", @oddmatches)."\n";
#print $#oddmatches + 1 ." matches found\n";
}
print "frequency of '$_' is $chars{$_}\n"
foreach (sort {$chars{$b} <=> $chars{$a}} keys %chars);
print "\n";
print "frequency of '$_' is $chars{$_}\n"
foreach (sort keys %chars);