my @ips_to_ignore = qw( 192.168.188.3 192.168.11.141 192.168.140.110 ); my $ignore = join "|",map(qr(\Q$_\E),@ips_to_ignore); $ignore = qr[^(?:$ignore)$]; while (){ chomp; print if ($_ !~ /$ignore/); } __DATA__ 192.168.188.3 192.168.11.141 192.168.140.110 192.168.188.33 192.168.187.12 ---output: 192.168.188.33 192.168.187.12