in reply to Re^2: Enlarging scalars
in thread Enlarging scalars

The original code had my $z = $z + 1;, this code has $z = $z + 1;

Like huck already said, "The extra my commands isolated the variables outside of the loop from any changes but it also meant the inner variables became almost static".

Using my $z you declare a second variable named $z, which shadows the first variable named $z declared at the top of your script. All statements mentioning $z will refer to that shadowing $z until execution leaves the block for the next loop iteration. In the next iteration, a new shadowing $z is created and all changes made previously have been lost.