in reply to search for nth occurrence of a pattern in a line
The third occurence of a string can be found by stepping through your substring with index. Since ',' is a simple string, not a pattern, index is ideal.
On the other hand, if you really do want to search for a particular pattern, here's one way to do it with respect to finding the third comma, using a regexp:
use strict; use warnings; my $string = "a,bc,d,efg"; if( $string =~ m/(?:,[^,]*){2}(,)/ ) { print $'; }
Dave
|
|---|