</code> to terminate the code -- some of the code is either getting lost or is causing the problem because of a shifted actual parameter list but until I see an unscrambled version of the code I can't be sure of this.
The 12th line of this has an unexpected ')' so I was loth to make too many assumptions
But apart from that my main first reaction is that you are mixing hash-style and list-style parameters in the actual parameter list to expect().
In Expect.pm, expect() has rather flexible parameter parsing which looks happy to consume just anything you care to pass it.
To be sure of how expect is using your parameters, you could use the debugger (-d at the end of the first line of your main program) and walk your way through how expect() deals with them (s to step, x to examine something).
Compare the values being read in (wherever the expect function does a shift()) with what the expect() function is trying to do and ask yourself if they match up.