#!/usr/bin/perl use strict; use warnings; use List::Util 'sum'; my @amount = (5, -6, 8, 10, 12, 3, 10); my $count = @amount; for (1 .. 2 ** $count - 1) { my @bit = split //, sprintf("%.${count}b", $_); my $total = sum( map {$bit[$_] ? $amount[$_] : 0 } 0 .. $#bit); print "$total\n"; }