Just don't print the header until you're ready to either print the page -or- generate a redirect.
A technique you can use to defer printing the header is to build up your HTML output into a string, and then do:
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
my $q = CGI->new();
my $do_redirect = 1; # for example only
# ... build the entire output into a string
$str = "This is your concatenated HTML doc";
if ($do_redirect) {
print redirect($url);
}
else {
print $q->header(), $str;
}
The idea is to wait until the absolute last second to print either header.
What can be asserted without proof can be dismissed without proof. - Christopher Hitchens