use strict; use warnings; my @log = ( 'May 18 12:01:01 bar: eht1 BS', 'May 19 13:58:01 foo: eth0: link down', 'May 19 13:58:11 foo: eth0: link up, 100Mbps, bar, lpa quux' ); foreach my $line (@log) { next unless (index($line, ": link")>=0); # skips BS # this is very fast # even running twice for # link up or link down is fast print "$line\n"; # focus on link mentioning lines here } #May 19 13:58:01 foo: eth0: link down #May 19 13:58:11 foo: eth0: link up, 100Mbps, bar, lpa quux