http://www.perlmonks.org?node_id=45735

Requires Net::LDAP Fill in the base DN, filter, hostname etc. in the appropriate points :} e.g. ldap.example.com for __HOSTNAME__, uid=avatar for __FILTER__ and dc=example,dc=com for __BASEDN__ I use q[] to avoid shell-quoting problems.
perl -w -MNet::LDAP -e '$entry = Net::LDAP->new(q[__HOSTNAME__])->sear +ch(filter => q[__FILTER__], base => q[__BASEDN__], scope => q[sub])-> +shift_entry; print $entry->dump'