ssh -fNg -L 6603:127.0.0.1:3306 remote_user@mysql.example.com #### my $ssh_pid= open("ssh -fNg -L 6603:127.0.0.1:3306 remote_user@mysql.example.com |") or die; my $dbh= DBI->connect("dbd:mysql..."); ... # tear down the connection kill -9 => $ssh_pid;