foreach(@$input){ # add this to make sure that we have combinations rather than permutations: next if( defined($v) && $_ < $v->{'number'} ); ...