#!/usr/bin/perl -w use strict; use Data::Dumper; my @list = (7,15,2); my @twoDmatrix =(); # the = () not really needed here. # take off "my" if you want to "clear" the matrix # later at some point, just: @twoDmatrix = (); my $rows = @list; # evaluation of @list in scalar context # yields 3, the number of elements # just replicated @list into multiple rows with # simple offset to make each row different # result is square matrix (num rows = num cols) my ($row, $col); for ($row=0; $row<$rows; $row++) { for ($col=0; $col<@list; $col++) { $twoDmatrix[$row][$col] = $list[$col]+ $row+1; } } print Dumper \@twoDmatrix; print "element [1][2] is $twoDmatrix[1][2] \n"; print Dumper $twoDmatrix[1]; #twoDmatrix[1] is #already a reference! no \ needed. __END__ $VAR1 = [ [ 8, 16, 3 ], [ 9, 17, 4 ], [ 10, 18, 5 ] ]; element [1][2] is 4 $VAR1 = [ 9, 17, 4 ];