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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.