Just for variety, a recursive solution suggests itself.
use strict;
use warnings;
sub add_to {
my ($target, $first_card, @others) = @_;
# Base cases
return [$first_card] if $first_card == $target;
return () if @others == 0;
# The set of cards adding up to target is
# the set of cards adding up to target that include first_card, AND
# the set of cards adding up to target that don't include first_card
return (map([$first_card, @$_], add_to($target-$first_card, @others)
+)
, add_to($target, @others));
}
my @hand = map 1+int(rand(10)), 1..7;
print "Hand is @hand\n";
print "@$_\n" for add_to(15, @hand);
Caution: Contents may have been coded under pressure.