in reply to CHECKING IF HEADER DEFINED

Most CGI related modules print their output so you could:

my $savedOutput; open my $saveOutput, '>', \$savedOutput; my $oldStdOut = select $saveOutput; # Call CGI stuff here select $oldStdOut; close $saveOutput; # process $savedOutput to clean up duplicate headers and other foibles + here print $savedOutput; # Output the cleaned up CGI output text
True laziness is hard work