Your questions in the Chatterbox and the ensuing clarification of the problem did make me go back to Mastering Regular Expressions and look up the exact meanings of the /s and /m modifier, thus you get a node here.
In your code, you're trying to match and extract the right data in one go. This can't be done that easily, since Perl only has non-capturing lookahead and there is no lookbehind in Perl (yet). So I use a different approach, capturing the data I want into $1 and then using that to store the address into @addresses.
Update: After amearse updated the data again, I updated my RE a bit, and now it also works with the data as posted. An extended reading of perlre or Mastering Regular Expressions might help here.
#!/usr/bin/perl -w use strict; my $i = do { local $/; <DATA> }; my @addresses = (); while ($i =~ /^From:\s+(.*)$/mg) { push @addresses, $1; }; print join "\n", @addresses; __DATA__ From: 21755603@ad.cd.net Date: Wednesday, April 11, 2001 10:08 PM From: 21742877@rd.cd.net Date: Wednesday, April 11, 2001 07:13 PM From: Grouch Date: Sunday, February 18, 2001 08:08 AM #Anything after "Grouch" does not get matched. From: 21742877@fr.tx.net Date: Wednesday, April 11, 2001 07:13 PM
In reply to Re: Expression matching
by Corion
in thread Expression matching
by amearse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |