my $sock = IO::Socket::SSL->new("$server") or die "Problem connecting via SSL to $server: ", IO::Socket::SSL::errstr(); my $ofh = select($sock); $| = 1; select ($ofh); my $IMAP = Mail::IMAPTalk->new( Socket => $sock, State => Mail::IMAPTalk::Authenticated, Username => $username, Password => $password, Uid => 0) or die "Could not query on existing socket. Reason: $@";