in reply to substring extraction
Your description doesn't completely tally with your code. If the file contains a single long string, then your while loop will only iterate once. However, to print out all, whitespace delimited words that either match or contain a given search term, you could use:
$string = 'this is a really long string (no really, it is!) that conta +ins a whitespace delimited word'; print $1 while $string =~ m[(\b\S*limit\S*\b)]gi;; ## All words, case +insensitive. delimited
|
|---|