use strict; use warnings; my @array = qw( 0 1 3 2 3 4 2 ); my @sums; for( "@array" ) { push @sums, $1 + $2 while m/(\d+)\s(?=(\d+))/g; } { local $" = ', '; print "[ @sums ]\n"; }