in reply to Evaluation of Simple Pop3 Client

Had your question been regarding "how do I parse HTML using a regular expression?", you would have been bombarded with a chorus of people saying "don't do that, use a module like HTML::Parser or it's derivatives". And in most cases they would be right. =) Why bother to reinvent parsing routines that someone else has done, and thousands of people use, and test, every day?

I'm going to give you the same advice for your project, don't parse an email message using a regex. Instead, use some of MailTools's CPAN modules to parse the message headers and body for you.

Here's your example re-worked to use the Mail::Internet module:

#!/usr/bin/perl -w use strict; use Net::POP3; use Mail::Internet; use constant POP3_SERVER => '10.10.10.10'; use constant USERNAME => 'username'; use constant PASSWORD => 'password'; my $pop3 = Net::POP3->new(POP3_SERVER) or die 'Could not open a POP3 connection'; $pop3->login(USERNAME, PASSWORD) or die 'Could not login'; my $messages = $pop3->list; foreach my $msg_num (keys %$messages) { my $mail = Mail::Internet->new( $pop3->get($msg_num) ); foreach my $header (qw(Date Message-Id From To Cc Subject)) { print "$header: ", $mail->get($header) if defined $mail->get($header); } #Get the message body, and possibly do something with it my $body = join '', @{$mail->body}; } $pop3->quit;