use strict; use Regexp::Assemble; my $re = do { open IN, shift || 'file_of_IPs_sought' or die $!; my $guts = Regexp::Assemble->new->add( map { chomp; quotemeta($_) } )->as_string; close IN; qr/\b$guts\b/ }; open LOGFILE, shift || 'logfile' or die $!; /$re/ and print while ; close LOGFILE; # update: if this is a pipe... /$re/ and print while <>;