$str =~s/.*(John).*/$1/; #### $str =~s{.* / | \. .*}{}gx; #### $str =~s{ (?: [^/]* / ){5} ( \w+ ) .* }{$1}x; #### print $str =~ /(John)/; print $str =~ m{ .* / (.+) \. }x; print $str =~ m{ (?: [^/]* / ){5} ( \w+ ) }x; #### my $s = 'John'; print $s if -1 != index $str, $s;