use strict; use warnings; my @netstat = `netstat -s`; my @matches=("invalid headers", "packets dropped"); foreach my $matches (@netstat) { my @results = grep(/@matches/, @netstat); #print "I am here\n"; print @results; }