Why are you terminating sends with "\r" and not "\n"?
my $exp = Expect->new;
$exp->expect(10, '~$ '); # prompt. using ssh keys so no password
$exp->expect(10, '~$ ');
... ls output ...
Connection to tak closed.
I would guess that the password input is accepting the "\r" as an input terminator (because login/password type input is wonky like that) but the proper input terminator for the type of session input and for general shell commands is "\n".
Just a guess, unless your Solaris is wonky or running some special shell (not csh/sh/etc) you should be using "\n". I've done a bunch of Expect stuff with Solaris, routers, switches, ... over ssh and never have I used "\r". I always use "\n" and have never had the sort of problem you seem to be having.