use CGI; ... $q = new CGI; my $login_ok = check_login($q); if ($login_ok) { $q->redirect(...); } else { $q->header(...); # emit html page }