$_ = "lothlorien"; m/ (?{ $i = 0 }) (. (?{local $i = $i + 1; }) )* lori (?{ $result = $i }) /xi; print "\$result=$result \$i=$i\n"; # this provides the same answer but is IMHO much easier to understand m/(.*)(?=lori)/ig; print "pos=", pos; # this is probably the best solution print "index=", index($_, 'lori');