http://www.perlmonks.org?node_id=1005447


in reply to Regex to compare (if) two strings (Uniquely - I will explain inside)

Further to previous post: A solution using a regex per OP request. No hashes. Note that the function now takes two strings, not a string and a hash. Tested, works.

sub scrabblicious { my ($word, # word to test for scrabble match to tray of letters $tray, # string with 'tray' of letters to select from ) = @_; return if not length $word; # special case: empty string $tray =~ s/$_//xms or return for map quotemeta, split '', $word; return 1; }

Update: Instead of
    $tray =~ s/$_//xms or return for map quotemeta, split '', $word;
using
    $tray =~ s/\Q$_\E//xms or return for split '', $word;
might be slightly faster because it avoids having  map quotemeta build another intermediate array. (Tested.)