Perl | rindex() Function Last Updated : 20 Nov, 2019 Comments Improve Suggest changes Like Article Like Report 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: Perl #!/usr/bin/perl -w $pos = rindex("WelcomeToGeeksforGeeksWorld", "eks"); print "Position of eks: $pos\n"; # Use the first position found as the offset # to the next search. # Note that the length of the target string is # subtracted from the offset to save time. $pos = rindex("WelcomeToGeeksforGeeksWorld", "eks", $pos - 3 ); print "Position of eks: $pos\n"; Output: Position of eks: 19 Position of eks: 11 Example 2: Perl #!/usr/bin/perl -w $pos = rindex("GeeksforGeeks", "eks"); print "Position of eek: $pos\n"; # Use the first position found as the # offset to the next search. # Note that the length of the target string is # subtracted from the offset to save time. $pos = rindex("GeeksForGeeks", "eks", $pos - 2); print "Position of eek: $pos\n"; Output: Position of eek: 10 Position of eek: 2 Comment More infoAdvertise with us Next Article Perl | rindex() Function C Code_Mech Follow Improve Article Tags : Perl Perl-function Perl-String-Functions Similar Reads Perl | rand() Function rand() function in Perl returns a random fractional number between 0 and the positive number value passed to it, or 1 if no value is specified. Automatically calls srand() to seed the random number generator unless it has already been called. Syntax: rand(range_value) Parameter: range_value: a posit 1 min read Perl | srand() Function The srand() function in Perl helps rand() function to generate a constant value each time the program is run. This srand() function uses the same parameter each time the rand() function is called for getting constant random value. Syntax: srand(seed) Parameters: seed : It is an integer value. Return 3 min read Perl | sin() Function This function is used to calculate sine of a VALUE or $_ if VALUE is omitted. This function always returns a floating point. Syntax: sin(VALUE) Parameters: VALUE in the form of float Returns: Function returns sine of VALUE. Example 1: Perl #!/usr/bin/perl # Calling sin() function $var = sin(5); # Pr 1 min read Perl | sprintf() Function sprintf() function in Perl uses Format provided by the user to return the formatted string with the use of the values in the list. This function is identical to printf but it returns the formatted string instead of printing it. Syntax: sprintf Format, List Returns: a formatted scalar string Example 1 min read Perl | return() Function return() function in Perl returns Value at the end of a subroutine, block, or do function. Returned value might be scalar, array, or a hash according to the selected context. Syntax: return Value Returns: a List in Scalar Context Note: If no value is passed to the return function then it returns an 2 min read Like