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