my $ldap = Net::LDAP->new(...) .... $ldap->unbind() my $socket = $ldap->socket(); close $socket if $socket;