in reply to Finding words within a character set

If your given a letter can it be matched more than once if it's only given once, or can it only be matched as many times as it's given?
ie a,e,h,r,t would match 'hater', but would it match 'hatter' or would it need to be a,e,h,r,t,t to match 'hatter'?

If the first is true pbeckingham's code will work, if not this may do what your looking for.
use strict; use warnings; my %words = map { $_ => countLetters($_)} qw/tar rat at attitude tap o +ther/; my $input = 'art'; my $input_letters = countLetters($input); my @matched_words; WORD: for my $word (sort keys %words) { for my $letter (keys %{$words{$word}}) { next WORD unless exists($input_letters->{$letter}) && $input_l +etters->{$letter} >= $words{$word}{$letter}; } push @matched_words, $word; } print "Matched words: @matched_words\n"; sub countLetters { my $word = shift; my %letters; $letters{$_}++ for split //, $word; return \%letters; }