in reply to
Handling Incoming Mail
Mail::Audit and Mail::ListDetector will almost certainly save you a lot of work in the long run. However if you'd rather use perl that you already understand, then you can always investigate procmail and just pipe the necessary mails through your program just like you're already doing from STDIN. That's going to be a bit more efficient and a bit less prone to newbie errors than extracting it from a mailbox once the system has delivered it, and has the advantage of also being realtime.