To make that work, you have to do what FoxtrotUniform did and declare and assign $bar before you use it, not afterwards as appears in the OP.
You can, of course, declare subroutines within the block of other subroutines, but you will face two issues. One, as FoxtrotUniform mentioned, the sub is still global anyway. The other is that if the inner sub references any lexical variables declared in the outer sub, strange things will happen. Open up perldoc perldiag and look for the message "will not stay shared."