fwiw,
rindex appears to be slightly faster:
use Benchmark qw(timethese);
my $s = "abcdefg";
timethese( 6_000_000,
{
rindex => sub { my $i = rindex( $s, "cde" ) },
index => sub { my $i = index( $s, "cde" ) },
}
);
Benchmark: timing 6000000 iterations of index, rindex...
index: 1 wallclock secs ( 1.14 usr + 0.00 sys = 1.14 CPU) @ 5263157.89/s (n=6000000)
rindex: 1 wallclock secs ( 1.02 usr + 0.00 sys = 1.02 CPU) @ 5882352.94/s (n=6000000)
their functional difference is that rindex starts from the end of the string, and index starts at the beginning. there is no difference in their usage.