my @totals; foreach my $row ( 1 .. 10 ) { my @output; foreach my $column ( 1 .. 10 ) { push @output , $column; } $totals [$_] += $output [$_] for 0 .. $#output; print join ',' , @output; } # print column totals here print "@totals";