VOOZH about

URL: https://www.geeksforgeeks.org/perl/perl-rindex-function/

⇱ Perl | rindex() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Perl | rindex() Function

Last Updated : 11 Jul, 2025
rindex() function in Perl operates similar to index() function, except it returns the position of the last occurrence of the substring (or pattern) in the string (or text). If the position is specified, returns the last occurrence at or before that position.
Syntax: # Searches pat in text from given Position rindex text, pattern, Position # Searches pat in text rindex text, pattern Parameters:
  • text: String in which substring is to be searched.
  • pat: Substring to be searched.
  • index: Starting index(set by the user or it takes zero by default).
Returns: -1 on failure otherwise position of last occurrence.
Example 1:
Output:
Position of eks: 19
Position of eks: 11
Example 2:
Output:
Position of eek: 10
Position of eek: 2
Comment
Article Tags:

Explore