BEGIN { # initialize stuff } END { # cleanup stuff } # code passes, possibly you're in a different module now... BEGIN { # initialize other stuff, # which might depend on first stuff } END { # clean up other stuff, # clean up might depend on first stuff still being here }