my $source_phrase = 'perl wisdom'; my $source_urword = join '', grep /\w/, sort_uniq( split //, $source_phrase ); # or whatever for ( keys %dictionary ) { delete $dictionary{$_} if /[^$source_urword]/ || length($_) > length($source_urword); }