Minor stylistic nitpicks before anything substantive: lexical filehandles are better than bareword globals like you've used, and you want to include $! in the error message so you know why the open failed.

open( my $ips, '<', 'TEST_IPS.txt' ) or die "Can't open IPS: $!\n";

That out of the way you're close but you don't consult %interesting_ips in any way to tell if you have a match. You also want to pull the list of matching IPs out differently.

#!/usr/bin/env perl use strict; use warnings; use Regexp::Common qw( net ); open ( my $ips_fh, '<', "TEST_IPS.txt" ) or die "can't open IPS: $!\n" +; open ( my $rules_fh, '<', "test_rules.txt" ) or die "can't open rules: + $!\n"; my %interesting_ips; while( <$ips_fh> ) { chomp; $interesting_ips{ $_ } = 1; } close( $ips_fh ); while( my $fw_line = <$rules_fh> ) { chomp( $fw_line ); my( @addresses ) = $fw_line =~ m{ ($RE{net}{IPv4}) }gx; for my $addr ( @addresses ) { next unless exists $interesting_ips{ $addr }; print qq{$.:interesting '$addr': $fw_line\n}; } } close( $rules_fh ); exit 0; __END__ $ perl pm_foo.plx 1:interesting '10.198.0.0': 133 bba33132-6192-51e8-4d78-c1b7bfd47251 a +ny V072-AklC-DB MOSSACSQLAdminGroup 10.198.0.0/16 10.210.0.0/16 MOSS_ +SQLAD_10-208-22-1/28 accept always RDP TCP17338 TCP18230 PING all + change 125213 157309 2:interesting '10.198.1.0': 136 a5ea4ee8-6192-51e8-0252-2017208af83d a +ny V071-AklC-Web ACHendersonRDPUsers 10.198.1.0/16 10.210.0.0/16 MOSS +_InternalWeb_10-208-22-16/28 accept always FTP all

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re^3: Sifting through firewall rules using a script by Fletch
in thread Sifting through firewall rules using a script by networkdude

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.