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


in reply to index() problem

Two approaches, one simple, one less so...

my $v = "lech_lecht"; #APPROACH ONE - single regex $cnt = 0; $v =~ m{ .*? (?{$cnt++}) lecht (?{$cnt+=4}) }x; print "$cnt\n"; #APPROACH TWO - feed regex output to length() $v =~ /.*?lecht/; print length $&, "\n"; __OUTPUT__ 10 10

Note, that for position, you may want to subtract one from the result, as these approaches give 1-based answers.

,welchavw