use constant N => 3; sub mmMxM { my ($ar_A, # ref. to array of ... $ar_B, # ref. to array of ... ) = @_; my @c = map [ map 0, 0..N ], 0..N; # AoA of zeros for my $i (0..N) { for my $j (0..N) { $c[$i][$j] += $ar_A->[$i][$_] * $ar_B->[$_][$j] for 0..N; } } return \@c; }