in reply to IP Parse and Count from logfile

That IP regex is not going to work for you. You've got too many capturing groups. (It isn't invalid, it just won't return what you think it does.) As it stands it will return the third digit group and a full stop.

I.E.
my $address = 'ip=111.112.113.114 '; my ($ip) = $address =~ /ip=(([0-1]?[0-9]{1,2}\.)|(2[0-4][0-9]\.)|(25[0 +-5]\.)){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))\s/; print $ip;
will print
113.
You would be better off using something like this:
my $tuple = qr'[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]'; my $address = 'ip=111.112.113.114 '; my ($ip) = $address =~ /ip=(($tuple\.){3}$tuple)\s/; print $ip;
Oh, and I pretty much agree with everything mscharrer said. See my take on it.
#!/usr/bin/perl use warnings; use strict; my %domains; my @domain_array = qw(ebay.com paypal.com americanbank.com usbank.com +americangreetings.com); my @bad_domains; $domains{$_} = undef for @domain_array; my $tuple = qr'[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]'; open my $log_domain, "logdata" or die "$!\n"; my ($host, $spf, $dkim, $ip); while (<$log_domain>) { ($host) = $_ =~ /domain=([\w\.]+?)\s/;#find regex for domain ($spf) = $_ =~ /spf=([0-4])\s/; #find regex for spf1 ($dkim) = $_ =~ /dkim=([0-4])\s/; #find regex for dkim1 ($ip) = $_ =~ /ip=(($tuple\.){3}$tuple)\s/; if (exists $domains{$host}) { $domains{$host}{counter}++; $domains{$host}{"spf$spf"}++; $domains{$host}{"dkim$dkim"}++; $domains{$host}{ip}{$ip} = undef; } else { push (@bad_domains , $host); } } close ($log_domain); my @stats = qw(dkim0 dkim1 dkim2 dkim3 dkim4 spf0 spf1 spf2 spf3 spf4) +; print "Domain, \"Domain Count\" "; print ucfirst($_).' ' for (@stats, 'IP'); print "\n"; foreach my $host (keys %domains) { print "$host,"; print $domains{$host}{$_} || 0,',' for ("counter",@stats); print keys %{$domains{$host}{ip}} ? (join ',', keys %{$domains{$ho +st}{ip}}) : 'none'; print "\n"; } print "The total amount of domains that we don't care about is ". scal +ar @bad_domains."\n";