in reply to Sharing a variable between subroutines

The most common way is:
{ my @array; sub foo { } sub bar { } }
Now @array is visible only within foo and bar. If you want to refer to it outside of those, you'll need to pass a copy or a reference to @array to the outside world.

(update) Of course, daveorg's got the answer to the obvious XY problem.