http://www.perlmonks.org?node_id=995754


in reply to Re: extract a specific string from input
in thread extract a specific string from input

.*? will get you the shortest sequence.

Usually that's correct, but not if there is overlap between the stand and the end delimiter. ATTAA is the shortest sequence that begins wtih ATT and ends with TAA, but ATT.*?TAA doesn't match it.

If overlapping matches need to be allowed, you can use for example

/((?=ATT).*?TAA)/