Just always use warn "foobar" if $DEBUG instead of print,
then it will do the right thingtm under both mod_cgi and
mod_perl.
For logging you should take a look at the Log::Agent module
available on CPAN.
Comment on RE: RE: Easy, elemental, but cool debug trick.