@_= (); for $_ ( 0..$#items ) { push @_, $_; push @return, [ @_ ] if when( @_ ); next if $target <= $sum[1]; for $_ ( ($_+1)..$#items ) { push @_, $_; push @return, [ @_ ] if when( @_ ); next if $target <= $sum[2]; for $_ ( ($_+1)..$#items ) { push @_, $_; push @return, [ @_ ] if when( @_ ); # ... } continue { pop @_; } } continue { pop @_; } } continue { pop @_; }