You should try using Net::OpenSSH instead.
In reply to Re: Script hangs when executing command over ssh by salva in thread Script hangs when executing command over ssh by eg2014