@a = qw/2 2 2 5/; #@a = qw/3 3 3 2 2 2 4 4 4/; $n = 4; powMatrix(\@a, $n); sub powMatrix { $m = shift; @f = @$m; $i = shift; $l = sqrt(@$m); while(--$i){ for($k = 0; $k < @$m; $k+=$l){ for($c = 0; $c < $l; $c++){ $o = $c; $z = 0; for($b = $k; $b < $k+$l; $b++){ $z += $f[$b] * $m->[$o]; $o += $l; } push (@g, $z); } } @f = @g; @g = (); } print "@f\n"; }