You could help us a little bit by putting a few comments in your code that explains what each part does. It takes a lot of time to try and decipher other peoples code and remember we're not being paid to do it. These are my guess's on how to make your code faster.
You're currently processing each line of your large file but really you just want to process those lines containing "mailD,id". then to get a big improvement in speed you want to try and do things via pipes rather than via loops. Why not use sed to extract this info outside the loop and just do it once for each user ie
Code:
#!/bin/bash
FILE=$1
grep "mailD,id" $FILE | \
sed 's/^.*mailD,id = ([A-Z0-9][A-Z0-9]( [A-Z0-9][A-Z0-9])+),.*$/\1/'` | \
sort | \
uniq | \
while read tmpmail
do
lda=`ldapsearch -a always -D cn=$user -w $pass -h 10.16.41.10 -p 16611 -s sub -L -b "id=$tmpmail,domainName=subsD,O=Test,C=MM" objectclass=common 2> /dev/null | grep mailo | perl -p -e 's/mailo: ([0-9]+)/\1/'`
perl -pi -e "s/$tmpmail/$lda/" log.log
done
exit
Before posting back that my code doesn't work etc please remember it's difficult to read your original code, there is no test data and no explanation of what's supposed to happen. You may need to use \( instead of ( in the sed command. This should be faster.
Mike