in reply to Curious result of using "my ... if ..."

This is the ever-popular "static local variable" thing. The variable really is local - if you try to access @a outside fn you will get an error.

The explanation, as I understand it, is that the action of the my in creating the variable is a one-time (compile-time, in fact) action so you get the same variable every time. But the assignment part is run-time and is skipped because of the modifier. This doesn't quite make sense to me, though, when you think about recursion, closures, etc.

IMHO it would be nice to have an explicit feature for this, but it seems unlikely in Perl 5. Meanwhile, you can do the equivalent on your own:

{ my @a; sub fn { # code that handles @a } }