in reply to mail::sendmail with an array of hashes

One rule I try to code by is to offload all the drugery to modules, so that I focus as much as possible on a higher level. The more you offload to modules, the shorter and clearer your code gets.

On that note, a few of your subroutines could be replaced by CPAN modules, which will shorten your code and free your focus.

Before I get into that, one question: Is it possible for you to filter and redirect the mail in real-time as they come in? If so, then you should look into Mail::Audit, which allows you to parse and filter mail pretty easily. Using this method should simplify the process significantly.

Ok, back to the code. The first thing I would do is look at your getDate() subroutine. Check out Date::Format which will format the date in the exact specification you desire, with much less code to maintain.

Next, you could replace the check_args() and usage() with Getopt::Declare or a combination of Getopt::Std and Pod::Usage. I prefer Getopt::Declare as it's argueably simpler to use and does what I want.

You can replace parse_head() with some of the MailTools modules. For example, the output from the Mail::POP3Client methods will be perfect input into Mail::Header and Mail::Internet's new() constructors. From there you can just use method calls to get at the From, To, Subject and Body of the message. No more parsing of the email messages with regexs, it's all done for you, very reliably.

Also, in your initial loop, you save a copy of the incoming message to a log file, I presume. The way you are opening up the file handle, using >, will clobber the file each time you write to it. My guess is that you need to use >>, which tells open() that you'd like to append to the file, not overwrite it.

At first glance you're probably thinking "this is alot of stuff to learn". That's true, but I would argue that, at some point, learning CPAN modules is almost as important as learning the core perl commands. At first it seems like alot, but every time you use a new module, the code you got working serves as a reference for next time. After a short period of time you have your own personal reference library and the time to implement similar tasks drops considerably.

Hope this helps.