#!/usr/bin/perl use strict; use warnings; use CGI qw/:standard/; print header, start_html(); my $letters = 'balphe_'; my (%lhash, @solutions, $blanks, $bcopy, $l); $blanks++ while $letters =~ s/[^a-z]//; $lhash{$_}++ for split //, $letters; open (DICT, "dict/dict1.txt") or die "error :!"; while () { $bcopy = $blanks; my %whash; chomp; $whash{$_}++ for split //; for $l (keys %whash) { no warnings; last if $lhash{$l} < $whash{$l} && ($bcopy -= $whash{$l} - $lhash{$l}) < 0; } push @solutions, $_ if $bcopy > -1; } print join "\n", sort {length($b) <=> length($a) || $a cmp $b} @solutions; exit; __DATA__ alpha beta gamma delta epsilon #### alephs behalf blahes bleach chapel Alpha Calpe abele abler ables albae aleph amble ample apple babel bagel baled baler bales basel bathe beach belah belay belch belga bella blade blahs blame blare blase blaze bleak blear bleat bleep bohea cable caleb chape cheap chela chelp Abel Ahab Alba Cape Cheb abbe abed abeg abet able ably ache ahem aiel aile alae alap albs alec alee ales alex aloe alps aped aper apes apex apse axel axle babe bade bael bagh baht bail bake bald bale bali balk ball balm bane bare base bash bate bawl bead beak beam bean beat beau beep bela bell belt bema beth bhan bile blab blah