use strict; use warnings; my @allIpsList = qw(10.1.1.10 10.1.1.17 10.1.1.125); my %ipsMatch = map {$_ => 1} @allIpsList; my $testFile = <)) { next if $line !~ /(\d+\.\d+\.\d+\.\d+)/; push @matched, $1 if exists $ipsMatch->{$1}; } return @matched; } #### 10.1.1.17 10.1.1.125