use strict; my @ips = ( "192.1.20.1", "192.1.20.2", ); my %ips = map { $_=>1 } @ips; open LOG, "<", "logfile" or die $!; while ( ) { #match ip-address if ( /(([0-9]+\.)+[0-9]+)/ ) { if ( $ips{$1} ) { # do found ip stuff here } else { #do other stuff here } } } close LOG;