Search code examples
stringperlstandard-library

Any perl standard library to check if a string contains a given substring


Given a query, I would like to check if this contains a given substring (can contain more than one word) . But I don't want exhaustive search, because this substring can only start a fresh word.

Any perl standard libraries for this, so that I get something efficient and don't have to reinvent the wheel?

Thanks,


Solution

  • This sounds like the perfect job for regular expressions:

    if($string =~ m/your substring/) { 
        say "substring found"; 
    } else { 
        say "nothing found"; 
    }