in reply to checking whether DBI connection made

If it's object-oriented, you could use a singleton pattern. (There's a non OO approach that looks very similar.)
my $single; sub new { return $single if defined $single; # set up args $self->{dbh} = DBI->connect(@args); $single = bless($self, $class); return $single; } # procedural { my $dbh; sub get_handle { return $dbh if defined $dbh; # handle arguments $dbh = DBI->connect(@args); } }