What you're thinking of are closures, see Tutorials: Closure on Closures, Creating Nested Functions
In reply to Re: Inner subroutines? by Anonymous Monk in thread Inner subroutines? by wsppan