in reply to Re: redrafted code
in thread redrafted code

Move the subroutine definition to somewhere else, for example to the top of your code, before the main part of the code starts.

Perl 5 parses the entire code before running it, so this is only relevant if your sub declaration relies on runtime effects.