http://qs1969.pair.com?node_id=1202757


in reply to Counting words

Your array only has a single element. I'll show how you would split each big string into smaller strings of 2 letters each using a regular expression. Each 2-letter word is stored in a hash.
use warnings; use strict; my $length = 2; my $str = "BEBEBEHUHUHUJJFAFALL"; my %cnt; while ($str =~ /(.{$length})/g) { $cnt{$1}++; } print "Found:\n"; print "$_ $cnt{$_}\n" for sort keys %cnt; __END__ Found: BE 3 FA 2 HU 3 JJ 1 LL 1