my @list = grep /\btest\b/, ; chomp @list; print "$_\n" foreach @list; __DATA__ This is only a test. Here's a line that doesn't contain the trigger text. This line contains test and test again. Now you see it, now you don't. Testing one two three. Test or not to test?