use warnings FATAL => 'all' ; use strict; use Data::Dump; use constant DEBUG => 0; use constant { DBPR_DD_1 => 1 && DEBUG, }; my $random = 'randam'; my %r_count; $r_count{$_}++ for split '', $random; dd \%r_count if DBPR_DD_1; for my $word (qw(a mad ran madnar madam ranx xxxxxx x)) { my %u_count = %r_count; my $ok = scrabblicious($word, %u_count); my $len = 2 + length $random; printf qq{%*s %sproperly formed from '$random' \n}, $len, qq{'$word'}, $ok ? ' ' : 'im'; } sub scrabblicious { my ($word, %u_count) = @_; for my $c (split '', $word) { return if --$u_count{$c} < 0; } return 1; }