http://www.perlmonks.org?node_id=910461


in reply to Re^2: Scope and references
in thread Scope and references

It might (or might not) be helpful to realize that my is an executable statement, not "just" a declaration.

update The following is more misleading than helpful. Please see the followup "puzzle" Re^4: Scope and references to see why. It produces a new instance of its argument(s), effectively unrelated (except by name) to previous instances created in that scope, and any previous instance has its reference count reduced by 1. If you have tucked a reference to a previous instance into an array, as you did in your first example, that keeps the reference count positive, so the instance does not get garbage collected. If there is no other reference to a previous instance, it ceases to exist as far as you are concerned.

This isn't simple stuff, most of us have been tripped up by something similar when we first started using lexical variables.