Caution: Untested code follows. I don't have an LDAP server to test this, but after reading the rather convoluted docs it looks like there is a sorted() method to help shorten your code a bit.
The "attrs" argument in the search() method may define the order in which attrs are returned by the attributes() method. The docs do not indicate this, but it looks right. $mesg = $ldap->search( base => $ldap_base, filter => "(&(objectclass=mailuser)($dsp_opt))", scope => 'sub', attrs => [ 'displayname', 'mail' ], ); my @sorted; foreach my $entry ( $mesg->sorted( 'mail', 'displayname' ) ) { push @sorted, [ $entry->attributes() ]; } You may need to add "nooptions => 1" to the attributes() method call. The docs assume a level of LDAP knowledge I do not possess. my @sorted; foreach my $entry ( $mesg->sorted( 'mail', 'displayname' ) ) { push @sorted, [ $entry->attributes( nooptions => 1 ) ]; } To make certain the order is as we want it, we should probably not assume the attribute order. my @sorted; foreach my $entry ( $mesg->sorted( 'mail', 'displayname' ) ) { push @sorted, [ $entry->get_value('displayname'), $entry->get_value('mail') ]; } I believe you originally wanted a list in a different format. "Display name" <[EMAIL PROTECTED]> my @sorted_addresses; foreach my $entry ( $mesg->sorted( 'mail', 'displayname' ) ) { push @sorted_addresses, sprintf '"%s" <%s>', $entry->get_value('displayname'), $entry->get_value('mail'); } # Or, only if it is understandable, my @sorted_addresses = map sprintf '"%s" <%s>', $_->get_value('displayname'), $_->get_value('mail'), $mesg->sorted( 'mail', 'displayname' ); HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>