@id =; chomp(@id); while($data = ) { chomp($data); foreach $id (@id) { if ($data =~ /$id/) { print OUT "$data\n"; } } } __comment__ sample contents of the ID_LIST: user45-16.dept12 user35-18.dept19 user05-14.dept10 sample contents of the DB: (3 MB of text) home--user45-16.dept12-ph#435 home66--user05-17.dept19-ddfg#5;v6.0234 home4--user35-18.dept19-hj#5 home87--user05-14.dept10-dfg#7;v2.0