in reply to preserve array from getting re-initilize

What you've done is fine, but I'm posting to comment on the other advice you've been given: use a state variable.

Unfortunately, non-scalar state variables are pretty much broken. Consider:

foo(); sub foo { state @verbose = 1..10; say shift @$verbose; }

gives an Initialization of state variables in list context currently forbidden error.

However, there are work-arounds, such as:

foo(); foo(); foo(); sub foo { state $verbose = [1..10]; say shift @$verbose; } __END__ 1 2 3

Using diagnostics states that "Constructions such as state (@a) = foo() will be supported in a future perl release".