in reply to pattern match

Your problem is that you aren't using a module from CPAN such as Mail::Box or Mail::MboxParser. Reinventing the wheel (badly) isn't a good thing!

gav^