use DBI; my ($user, $pass) = ('joe', 'joe'); my $dbh = DBI::connect('dbi:mysql:database=thisun',$user,$pass,{RaiseError=>1}) or die $!; # now connected to thisun $dbh->do('use thatun'); # now connected to thatun