in reply to Check if one string is a substring of another.
In terms of regular expression, here is one way. Here i assume $s1 as longer string. If $s2 is longer, change the below code as vice versa.
my $s1 = 'foofoo'; my $s2 = 'foo'; print "substring" if ($s1 =~ /\Q$s2\E/); #if $s1 is longer print "substring" if ($s2 =~ /\Q$s1\E/); #if $s2 is longer
updated: Eventhough regex is one way, as davorg suggested index is the best solution for this.
Prasad
|
|---|