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

monkfan has asked for the wisdom of the Perl Monks concerning the following question:

Most revered monks,
The built-in index function seems to be able to recognize only the first substring given two identical substrings from a string. My code below:
#!/usr/bin/perl -w use strict; my $str = 'NNNNNATCGNNNNATCG'; my @substr = qw(ATCG ATCG); foreach (@substr) { my $id = index($str,$_); print "$id\n"; }
Returns:
5 5
How can I overcome this problem such that the index function can recognize the second substrings in the correct position? Returning this instead:
5 13

Regards,
Edward