I'm afraid you haven't made yourself very clear about how these things are put together. Specifically, it sounds like 2) and 3) are completely separate scripts from the first one. That said, I would like to mention that, depending on your host and what sorts of access you have, procmail might be a very simple way to make sure your perl script is called once for each mail as it comes in. Much simpler than polling a mailbox.
Beyond that, I'm afraid you'll have to post more about exactly what problems you're running into. Consider breaking the problem into smaller pieces and explaining what you're doing with each of them.