my toPrint=""; if(...) $toPrint .= "Error message1\n" if(...) $toPrint .= "Error message2\n" if ($toPrint) print $toPrint;