If what you're parsing is a file full of e-mails, I'd recommend going straight for the Mail-Tools.
Mail::Util will break up a file full of mail messages into individual messages.
Mail::Internet can be used to parse out those messages, and
Mail::Header can be used to parse that header. Once you're dealing with headers individually, your problem becomes much simpler.
stephen