use strict; use warnings; use IO::Uncompress::Bunzip2 (); use Net::Subnet; my $filename = "debug.log.bz2"; my $fh = IO::Uncompress::Bunzip2->new($filename) or die "bunzip2 $filename: $IO::Uncompress::Bunzip2::Bunzip2Error"; my $matcher = subnet_matcher qw(72.46.130.0/24); while (<$fh>){ my @ips = m/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25 +[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/g; next unless @ips; next unless grep { $matcher->($_) } @ips; print; }