You don't want to try to define a named sub inside of another named sub! You can get away with it if you only use global variables, but you never want to do it with lexicals.
You have just triggered the infamous puzzling, "variable will not stay shared" warning. See Re (tilly) 9: Why are closures cool? which tries to explain what Perl is trying to warn you about and why there is no good resolution to the problem.