I tend to prefer a recursive approach for things like this; makes it easier to generalize.
The following is kind of brute force, but I think it's correct:
gen( 5, 50, 0, sub { print "@_\n" } );
sub gen
{
my( $cols, $max, $used, $found, @vec ) = @_;
return $found->( @vec, $max-$used ) if $cols == 1;
gen( $cols-1, $max, $used+$_, $found, @vec, $_ )
for 0 .. $max-$used;
}
Update:
I passed 50 for the 'max' value here because it gives the result you want when going to 100 by 2's.
Just multiply every number in every cell of the result by 2.
Similarly, if you want to go to 100 by 5's, pass 20, and multiply all the numbers in the result by 5.