in reply to Working with files

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.

Replies are listed 'Best First'.
Re^2: Working with files
by AmberThai (Initiate) on Jan 18, 2016 at 12:27 UTC

    Matched:'abc clothes','.mall abc something doing shopping at the .mallabc'

    I expected it to match :"abc abcabc"

    And I opened a new thread not knowing if I will get an answer ,sorry :D

      If you change the middle quantifier from non-greedy to greedy, it will try to match the longest possible part.