See here regarding mod_perl and using variables in subroutines.
In reply to Re^2: CGI scoping question by poj in thread CGI scoping question by WoodyWeaver