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