while() { chomp; if ( /(Wilma)([\w\W]{5})/i ) { print "Matched: |<$1> <$2>\n"; } else { print "No match: |$_|\n"; } } __DATA__ This is a line that has the name fred in it. This is a line that does not. This is a line that has the name barney in it. This is fred. This is notfred. Hello Fred Flintstone! Hello Fred! Allo allo, Alfred! Cheerio Mr. frederick! Hello Mr. Slate! Hello FRED! Hello Fred! Hello fred! This is some wilma text with some words in it this is fred. This is wilmafred. This is some more wilma text fred. Mrs. Wilma Flintstone wilma&fred wilma but not barney I saw Wilma yesterday. #### perl 732070.pl No match: |This is a line that has the name fred in it.| No match: |This is a line that does not.| No match: |This is a line that has the name barney in it.| No match: |This is fred.| No match: |This is notfred.| No match: |Hello Fred Flintstone!| No match: |Hello Fred!| No match: |Allo allo, Alfred!| No match: |Cheerio Mr. frederick!| No match: |Hello Mr. Slate!| No match: |Hello FRED!| No match: |Hello Fred!| No match: |Hello fred!| Matched: | < text> Matched: | Matched: | < text> Matched: | < Flin> Matched: | <&fred> Matched: | < but > Matched: | < yest>