Just to reinforce what tybalt89 said, there are several Expect-related modules in perl. Among them are:
If I've left out someone's favorite, I apologize--I think I have used each of those in the past on various projects. I should note there are also several modules that play nicely with Expect, such as Net::OpenSSH and its variants.
I would suggest you take Corion's suggestion to heart and consider looking at (passwordless) SSH key access. Under OpenSSH keys can be locked down to allow only from a particular set of hosts and/or to allow execution of only certain commands you specify, both of which may prove useful in increasing the security of the system you are assembling.
Hope that helps.