use strict; use warnings; open(OUTNOMATCH, ">nomatch.out") or die "Couldn't write to file $!"; open(OUTMATCH, ">match.out") or die "Couldn't write to file $!"; sub match_internal { #Separate internal/external addresses use Net::IP::Match::Regexp qw( create_iprange_regexp match_ip ); my $my_ip = $_[0]; my $regexp = create_iprange_regexp( qw( 192.168.0.0/16 10.10.0.0/16 192.3.3.0/23 192.168.24.0/21 10.0.0.0/8 ) ); if (match_ip($my_ip, $regexp)) { print OUTMATCH "$my_ip\n"; } else { print OUTNOMATCH "$my_ip\n"; } } sub uniq_ip { # locate and remove duplicate addresses my @list = @_; my @uniq_ip = keys %{{ map { $_ => 1 } @list }}; } sub sortme { # sort all addresses my @array = @_; my %hashTemp = map { $_ => 1 } @array; my @array_out = sort keys %hashTemp; } sub main_loop { #main loop that performs all logic and munging my @item; my @uniq_out; while (<>) { (my $field1, my $field2) = split /DST=/, $_; if ($field2 =~ m/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) { push (@item, $1); } } @uniq_out = uniq_ip(@item); foreach(@uniq_out) { match_internal($_); } } main_loop();