my %match; if (open (FH1, "first.txt")) { while () { if (/^\s+(\S+)/) { $match{$1} = 1; print "Found $1\n"; } } close (FH1); } if (open (FH2, "data.txt")) { while () { if (/^\s+\S+\s+\S+\s+(\S+)/) { if ($match{$1}) { print "Match on $1\n"; } else { print "NO match on $1\n"; } } } close (FH2); }