I normally call a sub, and exit from there, for instance if im checking for an empty string, id do something like
if ($val eq ""){
&error;
}
sub error{
print <<ErrHtml
<html>
<head>
<title>Error</title>
</head>
<body>
An error occurred
</body>
</html>
ErrHtml
exit; #exit so the script stops here
}