http://www.perlmonks.org?node_id=1026291


in reply to adding items, but with interim results

I know you probably want a solution in Perl 5, but here is one in Perl 6, because it hapepns to be very short:

$ perl6 -e 'say [\+] 0, 1, 3, 2' 0 1 4 6

Enclosing an infix operator like + with square brackets applies it to a list, as if you had written  0 + 1 + 4 + 6. The [\infix] for also returns the intermediate results.

Mnemonic: the [\ has the shape of a triangle, just like the list of expressions that is generated from it:

0 0 + 1 0 + 1 + 4 0 + 1 + 4 + 6