use Apache::Registry; my $r; eval { $r = Apache->request }; if (defined $r) { $r->content_type(...); ... $r->send_http_header; } else { print "Content-Type: ... \n"; ... print "\n"; }