--- name: index status: documented runtime: pp source: src/runtime/pp/strings/search.rs --- ```{index} single: index; Perl built-in (pp runtime) ``` # index ## Synopsis ```perl $pos = index($string, $substr); $pos = index($string, $substr, $start); ``` ## Description Finds the first occurrence of a substring within a string. Searches STRING for the first occurrence of SUBSTR starting at character position START (default 0). Returns the zero-based character position of the match, or -1 if the substring is not found. Positions are in characters (not bytes), so this works correctly with multi-byte UTF-8 strings. An ASCII fast path avoids the overhead of character-index conversion when both operands are pure ASCII. When the `OPpTARGET_MY` flag (0x10) is set, the result is stored directly into the pad slot rather than pushed to the stack. ## See also rindex, substr, pos