#!/usr/bin/perl -w use strict; use Data::Dumper; #---- The wrong way my @container=(); my @a=(); for (my $i=0; $i <=1; $i++){ @a=(); $a[$i] = 99; push @container, \@a; } print Dumper(\@container); #### #!/usr/bin/perl -w use strict; use Data::Dumper; #By using careful scoping, you can control allocation of an array that you intend to reuse. #---- The right way { my @container=(); for (my $i=0; $i <=1; $i++){ my @a=(); #@a is declared INSIDE the scope of the loop $a[$i] = 99; push @container, \@a; } print Dumper(\@container); }