my @lines = qw/marge homer bart jerry maggie george elaine kramer lisaross chandler fibi joey monica rachel batman robin catwoman batgirl superman thetick hollywood studio universal compton harbor downtown monica venice oc oxnard ventura oaks/; my @kwords = qw/bart maggie monica pete/; my @matches = map { my $kword=$_; grep /\b$kword\b/, @lines } @kwords; { local $, = "\t"; print @matches; }