Here's a link to a page that talks about logging in via Perl and SSH. It's a little long, so I didn't read it very well. It may or may not be the solution you're looking for.
This link appears to be some sort of commercial product.
A link to an Expect module modified for SSH usage.