use Memoize; BEGIN { *dbh = memoize(sub () { DBI::->connect(...) }) } dbh()->foo; # connect and do foo. dbh()->bar; # use cached object and do bar.