I'd like to add another layer of complexity. I connect to MySQL from a CGI::Application web app. CA recommends using a teardown sub to disconnect as follows:
sub teardown {
my $self = shift;
# Disconnect when we're done
$self->param('DBH')->disconnect();
} # teardown