in reply to qx//, ssh -t (pseudo-tty) and sudo

sudo has the -S option which causes it to read from stdin. This means you don't have to worry about the -t option to ssh, tty's, and all that stuff. The stdin is piped through ssh so open with pipe or IPC::Open3 will work fine.