use strict; use warnings; use 5.010; my $str = "The black cat climbed the green tree"; say index $str, 'cat'; # 10 say index $str, 'dog'; # -1 say index $str, "The"; # 0 say index $str, "the"; # 22
It will search for the location of the second string in the first string. Returns -1 in case the string could not find the second string. You can also add a 3rd parameter that will tell index where to start the serach from.
Published on 2020-05-16