Here's one way to do it:
while (<>) {
if (/wilma/) {
if (/fred/) {
print;
}
}
}
This tests /fred/ after we find /wilma/ matches, but fred could appear before or after wilma in the line; each test is independent of the other.
If you wanted to avoid the extra nested if test, you might have written something like this:
while (<>) {
if (/wilma.*fred|fred.*wilma/) {
print;
}
}
This works because we'll either have wilma before fred or fred before wilma. If we had written /wilma.*fred/, that wouldn't have matched a line like fred and wilma flintstone though that line mentions them both.
We made this an extra-credit exercise because many folks have a mental block here. We showed you an "or" operation (with the vertical bar, |), but we never showed you an "and" operation. That's because there isn't one in regular expressions. If you want to know if two patterns are both successful, just test both of them.