Thanks for the answers. I'm going with moving the subs and defining any required variables in main as "our". The outer sub is only executed once anyway (cgi web page), and any other fallout is almost certainly a bug.