my $q = CGI->new; check_https($q); sub check_https { my ($cgi) = @_; unless ($cgi->https) { my $url = $cgi->url(-path_info=>1, -query =>1); s/^http:/https:/ or die "Unsupported URI scheme, or https detection error"; print $cgi->redirect($url); exit; } }