Here is a simple brute force enumeration for splitting 100 into 5 parts, each a multiple of 2:
my $step = 2;
for (my $a1 = 0; $a1 <= 100; $a1 += $step) {
for (my $a2 = 0; $a2 <= 100-$a1; $a2 += $step) {
for (my $a3 = 0; $a3 <= 100-$a1-$a2; $a3 += $step) {
for (my $a4 = 0; $a4 <= 100-$a1-$a2-$a3; $a4 += $step) {
my $a5 = 100-$a1-$a2-$a3-$a4;
last if $a5 < 0;
print "$a1 $a2 $a3 $a4 $a5\n";
}
}
}
}
If you want to get fancier, such as varying the number of parts, you may want to check out
Algorithm::Loops