I would say the problem lies in the "switching" of files. On the next iteration of the loop, result of the previous grep is used as input. Therefore, in your example, the word "LOVE" is being searched only on lines already containing "WE".
You should grep always the original input file. But it would be faster to search for all the words at the same time, i.e. changing "WE LOVE" to "WE\|LOVE" (by something like $wrd =~ s/ /\\|/g) and greping just for this.
In reply to Re: Online GREP problem
by choroba
in thread Online GREP problem
by gfausel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |