# wrong beaviour as it doubles the memory # first code of my previous post, very similar to the OP one my $x = 'a' x (2**30); # RIGHT beaviour, it does NOT double memory used # second code posted above my $x; foreach my $order ( qw(20 24 30 32) ){ $x = 'a' x ( 2 ** $order ); ... # RIGHT beaviour, even with my $x declared inside the foreach loop foreach my $order ( qw(20 24 30 32) ){ my $x = 'a' x ( 2 ** $order ); ...