in reply to Parsing a mail

There are many CPAN modules available for parsing MIME documents. In particular, MIME::Parser and MIME::Tools. Both modules have abundant documentation and examples.