int indexNth( SV *haystack, SV*needle, int nth ) { STRLEN lh, ln, i, j; char *h = SvPV( haystack, lh ); char *n = SvPV( needle, ln ); for( i = 0; i < lh; ++i ) { for( j = 0; j < ln; ++j ) { if( h[ i + j ] != n[ j ] ) goto nomatch; } if( --nth == 0 ) return i; nomatch:; } return -1; }