in reply to defining variables using my - subroutines
The question is nonsensical because subroutines in Perl only take and return lists, not variables. If you define tightly-scoped variables in a subroutine, they are not available outside of it. Instead of paraphrasing your approaches in English prose, show the code/attempts you already have, then we can properly discuss it.
In Section
Seekers of Perl Wisdom