use feature qw(say state); my @widths = (2, 6, 5, 7); my @partitions = map { state $c = 0; [$c, $c += $_] } @widths; say '[', join(', ', @$_), ']' for @partitions; #### [0, 2] [2, 8] [8, 13] [13, 20] #### [2, 2] [8, 8] [13, 13] [20, 20]