my $connectionerror; sub dbconnect { my $db = DBI -> connect(...) || &connectionerror; if ($db && $connectionerror != 1) {...} } sub connectionerror { $connectionerror = 1; }