sub scrabblicious { my ($word, # word to test for proper match to tray of letters $tray, # string with 'tray' of letters to select from ) = @_; return unless # handles word empty string (my $rx = join '', sort split '', $word) =~ s{ (.) \1* } { $+[0] - $-[0] > 1 ? qq/(?= (?: .*? \Q$1\E){@{[ $+[0] - $-[0] ]}})/ : qq/(?= .*? \Q$1\E)/ }xmseg; return $tray =~ m{ \A $rx }xms; }