Here is a simpler program that accomplishes the same thing for up to 32 checks:
my @check = (10, 5, 13, 3, 15, 1);
my $desired = 16;
foreach my $index (0..2**@check-1) {
my $sum = 0;
foreach my $pos (0..@check-1) {
my $bit = ($index >> $pos) % 2;
$sum += $bit * $check[$pos];
}
if ($sum == $desired) {
my @combo;
foreach my $pos (0..@check-1) {
push @combo, $check[$pos] if ($index >> $pos) % 2;
}
print join " ", @combo, "\n";
}
}
Here I index the possibilities with a simple integer expressing a binary combination of checks.
Timing was 55 milliseconds on an Athlon 2100.