use MongoDB; our $conn; if(!defined($conn)){ $log->info("Creating new DB connection"); $conn = MongoDB::MongoClient->new; } else{ $log->info("DB connection already exists"); } ...do something...