example of a 3x3: my @m = ([0,0,0], [0,0,0], [0,0,0]); #### #!/usr/bin/perl -w use strict; use Data::Dumper; my @sq_matrix_3x3; my @list = (1,2,3); foreach (@list) { push (@sq_matrix_3x3, [0,0,0]); #creates a row with 3 elements } print "3x3 Matrix: "; print Dumper \@sq_matrix_3x3; #### my @another_2D; for (my $x=0; $x<3; $x++) { for (my $y=0; $y<3; $y++) { $another_2D[$x][$y]=0; } } print Dumper \@another_2D; __END__ prints: 3x3: $VAR1 = [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ]; # print Dumper \@sq_matrix_3x3; #these both produce the same output # print Dumper \@another_2D;