Hrrm, this will work, but boy is it ugly.
Code:
cat /var/log/maillog |grep reject|awk -F : '{print $6}'|cut -d [ -f 2|cut -d ] -f 1
explanation in case you're not familiar with these commands (and for newcomers who find this thread, so the explanation will cover things you know.)
cat /var/log/maillog just echoes the whole maillog. Then it's piped to grep reject, only getting the lines that have reject in them.
Then, send that to awk, using a : as a delinator. (After some experimentation, that seemed the easiest and got the least amount of extra stuff.) Get the 6th field which gives us
RECEIPT from unknown[78.93.134.157]
Then, using cut (at this point, there's probably a better way to just get the numbers, but it's early in the morning) using [ as delinator and taking the second field, which gives us the 78.93.134.157 with the ] on the end. The last pipe to cut gets rid of that.
There has to be a better way, and I'm sure one of the more skilled people will have a suggestion, but this could get you started. I can't think clearly yet.
Edit: I know you said php or perl, but I don't know either of them.
I have a feeling perl would be the best choice.