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

Doing IO with TTYs, pseudo or otherwise, can be tricky. You might want to look at Net::SSH or Expect to do the hard part for you.