in reply to position of the last match in RE
However, if you're just looking for fixed substrings, you may prefer to use index instead:$_ = "abcdmefg"; if ($_ =~ /m/g) { print "matched 'm' at ",pos,"\n"; }
Keep in mind that pos returns the location where the previous match ended, while index returns the location where the substring begins. Thus, these two snippets give 5 and 4 respectively.$_ = "abcdmefg"; if (($pos = index($_, 'm')) >= 0) { print "found 'm' at ", $pos, "\n"; }
|
|---|