my @matches = grep { my $term = $_; grep{ $_=~/$term/}@lines } @terms;