Something like the following? It slows the algorithm terribly, though...
#!/usr/bin/perl use warnings; use strict; use feature qw(say); my %lc_words; my $dict = shift; my $FH; open $FH, '<', $dict or $FH = *DATA; while (<$FH>) { chomp; next if length > 8; my $lc = lc; $lc_words{$lc} = 1; } say scalar keys %lc_words; my %sorted_count; for (keys %lc_words) { my @letters = sort split //; my $sorted = join q(), @letters; $sorted_count{$sorted}++; } say "$_: $sorted_count{$_}" for sort { $sorted_count{$a} <=> $sorted_count{$b} } keys %sorted_count; print '-' x 78, "\n"; my %summed = %sorted_count; for my $length (1 .. 7) { warn $length; for my $sorted (grep $length == length, keys %sorted_count) { my $regex = join '.*', split //, $sorted; for my $longer (grep $length < length, keys %sorted_count) { $summed{$longer} += $sorted_count{$sorted} if $longer =~ $ +regex; } } } sub merge { my ($str1, $str2) = @_; my $merged = q(); while(length $str1 . $str2) { my $char1 = substr $str1, 0, 1; my $char2 = substr $str2, 0, 1; if ($char1 eq $char2) { $merged .= substr $str1, 0, 1, q(); substr $str2, 0, 1, q(); } elsif ($char1 ne q() and $char1 lt $char2 or $char2 eq q()) +{ $merged .= substr $str1, 0, 1, q(); } else { $merged .= substr $str2, 0, 1, q(); } return if length $merged > 8; } return $merged; } warn "Merging...\n"; my $added; while (1) { $added = 0; my @shorter = grep 8 > length, keys %summed; for my $str1 (@shorter) { for my $str2 (@shorter) { next if $str1 le $str2; my $merged = merge($str1, $str2); if (defined $merged and $str1 ne $merged and $str2 ne $merged) { next if exists $summed{$merged}; $summed{$merged} = $summed{$str1} + $summed{$str2}; $added++; } } } last unless $added; warn "Added $added\n"; } say "$_: $summed{$_}" for sort { $summed{$a} <=> $summed{$b} } keys %summed; __DATA__ abcd acdb adbc dabc bcad efgh fgeh hegf egfh fegh abcdxy efghlm
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re^7: Challenge: 8 Letters, Most Words by choroba
in thread Challenge: 8 Letters, Most Words by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.