in reply to Re^2: How can I access package variables in a dynamic way
in thread How can I access package variables in a dynamic way

The best approach would be to create the appropriate hash yourself then:

my %foreign_variables = ( address_1 => \$Person::address_1, address_2 => \$Person::address_2, address_3 => \$Person::address_3, # ... );

Replies are listed 'Best First'.
Re^4: How can I access package variables in a dynamic way
by bangor (Monk) on Feb 12, 2019 at 15:44 UTC
    I do like this, but in my actual use case (which I didn't mention, sorry) I don't know how many $nums there will be.

      In that situation, you will have to inspect the hash %Person:: and hope that all the variable slots have actually been assigned.

        Agreed... although this is really moving into "hack" territory, my code from here could be extended to:

        my $amax; for ($amax=1; exists $Person::{"address_$amax"}; $amax++) {} $Person::addresses = sub{\@_}->( map { no strict 'refs'; ${"Person::address_$_"} } 1..$amax-1 );