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


in reply to Regex help

+ is greedy and will match as many of whatever it applies to as it can. Generally it is smart to avoid . and use an explicit set of characters to match. In this case everything except / looks like it may be what you want:

$str =~ m!(.+)(/path/)([^/]+)(/.+)!

Note that I used ! as the regex delimiter to avoid having to quote all the / characters.

True laziness is hard work