Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I have a string contains email address of the form
$string = "John <john@test.com>; Cris James <cris@test.com>";
I would like to store email address in a variable as
$output="john@test.com;cris@test.com";
How can I do that?
Thanks

Replies are listed 'Best First'.
Re: Extracting email addresses
by pc88mxer (Vicar) on Feb 28, 2008 at 05:17 UTC
    Check out the Email::Address module. The parse() method will parse a line and return a list of address objects. Then just use the user() and host() methods on the returned addresses to create your output string.
Re: Extracting email addresses
by NetWallah (Canon) on Feb 28, 2008 at 06:13 UTC
    One way is to use the split function, using ";" as the delimiter.

    Then extract items between the "<" and ">" using a regular expression, or a use Regexp::Common::Email::Address to extract things that look like an e-mail address.

         "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom