my $what = "fred|barney"; while (<>) { chomp; if ($_ =~ ($what){3}) { print "It's in there.\n"; } else { print "Not there.\n"; } }