use strict; use Mail::Address; my $hdrstring = ""; my $checknext = 0; open( M, "pegasus-mail.file" ) or die $!; while () { if ( /^(?:To|From|Cc|Bcc): (.*)/ ) { $checknext++; $hdrstring = $1; } elsif ( $checknext and /^\s+\S.*/ ) { $hdrstring .= $_; } else { $checknext = 0; if ( $hdrstring ) { my @addr = Mail::Address->parse( $hdrstring ); for my $a ( @addr ) { print $a->name, " <", $a->address, ">", $/; } $hdrstring = ""; } } }