for $word (@large_wordlist) { $word = '_'.$word.'_'; my $len = length($word); my $flen = $len; my $i; for ($i=0; $i<$flen; $i++) { $$ngram{substr($word,$i,5)}++ if $len > 4; $$ngram{substr($word,$i,4)}++ if $len > 3; $$ngram{substr($word,$i,3)}++ if $len > 2; $$ngram{substr($word,$i,2)}++ if $len > 1; $$ngram{substr($word,$i,1)}++; $len--; } }