use Data::Dump; my $acl_grammar = do { use Regexp::Grammars; qr{ # In case you need it, uncomment this line: # # Match this... # According to these definitions: access-list extended permit | deny tcp | udp | ip | object-group object-group object-group | host | object-group | host | eq | range |
any | | \d+ <.octet> ( <.dot> <.octet> ){3} \( [^()]* \) \w+ \d{0,3} \. <.capword> ** _ \p{Lu} \p{Alnum}+ }x; }; while (my $input = ) { if ($input =~ $acl_grammar) { say "MATCHED"; dd \%/; # parse tree of a successful match # appears in the %/ variable } else { warn "CAN'T MATCH: $input"; } } __END__ access-list V420_IN extended permit object-group Symantec_Service_Group object-group Symantec_Clients Symantec_Servers (all 3 object groups) access-list V421_IN extended permit object-group Symantec_Service_Group 10.148.0.0 255.254.0.0 host 10.149.16.40 (One service group and two network addresses) access-list V422_IN extended permit object-group Symantec_Service_Group any any (Source & Destination any) access-list V423_IN extended permit tcp any any range 137 139 (with a range of TCP ports) access-list V424_IN extended permit tcp any any eq 445 (with a single service port)