sub can_play_card { my $cost = shift; # hashref of type => amount required my $mana = shift; # arrayref of mana types player holds my $pool = join '', map {printf "%2s", $_} sort @$mana; my $check = join '(?:..)*?', map {"(?:.$_|$_.)"} map {("$_") x $cost->{$_}} sort keys %$cost; return $pool =~ m/$check/; }