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


in reply to Re^2: Regex expression to match...
in thread Regex expression to match...

Quantifiers used in that way do not do what you think they will:
use strict; use warnings; my @strings = qw( /help/one/one/one/bar/something_here /buy/cash/buy/water/water/water/baz/nothing_here ); for (@strings) { if (m{(\w+/){2,}}) { print "Dup is '$1'\n"; } } =prints bar/ baz/ =cut

Even if it did work, you'd still need to add boundary conditions so that a sub directory that is a suffix of the previous directory wouldn't match. Also, if the duplicate is on the end, it wouldn't have a trailing /.

Don't worry, at one point, I also thought a quantifier should work in that way, but that's specifically why they allow \1 in the LHS.