sub make_report1 { my $dbh = shift; my $newdbh=0; if (!defined $dbh) { $dbh = &_get_dbh; $newdbh=1; } ... # close the database connection if opened here $dbh->disconnect() if $newdbh; }