I don't believe this is the complete program, because I don't see where your variables are being defined. If the
my statements are inside a loop, by definition you can't see the variable outside the loop (and
use strict; use warnings; are correcly telling you so.)
So, please show the program you are trying to run, and we'll try this again.