use Benchmark; $letters = 'chuncii_'; $lcount = length($letters); while ($letters =~ /[^a-z]/) { $letters =~ s/[^a-z]//; $blanks++; } $lhash{$_}++ for split //, $letters; $t0 = new Benchmark; open ($handle, 'dictionary.dat'); while (<$handle>) { chomp; $w++ if scrabble($_); $c++; } close ($handle); $t1 = new Benchmark; $td = timediff($t1, $t0); print "the code took:",timestr($td),"\n"; print "$w matches from $c words"; sub scrabble { return 0 if length($_[0]) > $lcount; my %wlhash; $wlhash{$_}++ for split //, $_[0]; $nf = 0; for (keys %wlhash) { return 0 if $lhash{$_} < $wlhash{$_} && ($nf += $wlhash{$_} - $lhash{$_}) > $blanks; } return 1; }