# untested, change to suit my @messages; if ( ....test.... ) { push @messages, "The error message"; } # more tests PrintError if @messages; sub PrintError { # any initial html stuff, or use a template print join('
', @messages); }