for(my $i=1; $i<=$x; ++$i){ for(my $j=0; $j<$y; ++$j){ for(my $k=0; $k<$y; ++$j){ $distance_mat -> [$i][$j][$k] = rand 1; } } }