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