#!/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; }