use feature qw(say state); my @widths = (2, 6, 5, 7); foreach (1 .. 2) { my @partitions = map { state $c = 0; [$c, $c += $_] } @widths; say '[', join(', ', @$_), ']' for @partitions; print "\n"; }