in reply to Expect Module problem

I suggest you use the following for your $string:

username@x.x.x.x
Because otherwise the remote user is expected to match the local user, which is not always the case, and certainly not something that you should rely upon.