FWIW, it works for me. Maybe the problem isn't the perl code, but how ssh is setup, E.G. for some reason it doesn't prompt your script at all? What if you try to ssh to localhost instead of a remote host? When you manually ssh in, are you prompted for a password? Should it match the regex /password: ?$/i ?
You don't mention what error the script is producing exactly....