Read perlre about "greedy" quantifiers. You're using a non-greedy quantifier, which will stop at the first .mall instead of the last.

As a recommendation, you get much better answers if you make it easy for people to replicate your problem. Instead of reading from a file, simply assign your data to a string:

my $line = 'abc clothes doing shopping at the .mall abc something doin +g shopping at the .mallabc'; my ($before, $between, $after) = /(.*?.clothes|.something)(.*?)(\.mall +.*)/; print "Matched: '$before', '$after'\n";

It's also often very good to show what you get and what you expect, ideally also with an explanation why you think you should get what you expect.

Also, why did you open a new thread? Re^2: Reading from files would likely also have received an answer.


In reply to Re: Working with files by Corion
in thread Working with files by AmberThai

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.