#! perl -slw use strict; my( $nName, $iName, $vrid, $state, $paddr, $nAddr, $oAddrs, @oAddrs ); die "File does not contain a Network name header" unless ( $nName ) = =~ m[Network\sname \s+ (\S+)]x; local $/ = "\nI"; while( ) { if( ( $iName, $vrid, $state, $paddr, $nAddr, $oAddrs ) = m[ (?=.*? nterface \s+ (\S+) ) (?=.*? VRID \s+ (\S+) ) (?=.*? State: \s+ (\S+) ) (?=.*? Primary\saddress: \s+ (\S+) ) (?=.*? Number\saddresses: \s+ (\S+) ( .+? ) (?=Monitored\scircuits:) ) ]smx ) { @oAddrs = split ' ', $oAddrs; print join ', ', $nName, $iName, $vrid, $state, $paddr, $nAddr, @oAddrs; ### This is the new code that allows it to process ### multiple networks within the same file. ### If the last interface record we read has a Network record ### appended to the end, then parse out and update the $nName variable. $nName = $1 if m[Network\sname \s+ (\S+) \s* \nI$]x; ### If you do not understand how this works, then you should try adding ### some print statements and play with this test script until you do understand. } else { warn "File did not match required format"; } } __DATA__ Network name A Interface WEB_A ggggggggg VRID 145 State: Master XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 194.551.205.250 Number addresses: 1 135.51.045.242 Monitored circuits: vbgghdfgdfg Interface WEB_B ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 2 135.51.05.22 321.654.987.111 Monitored circuits: vbgghdfgdfg Interface WEB_C ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 3 135.51.05.22 123.456.789.001 321.654.987.111 Monitored circuits: vbgghdfgdfg Network name B Interface WEB_A ggggggggg VRID 145 State: Master XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 194.551.205.250 Number addresses: 1 135.51.045.242 Monitored circuits: vbgghdfgdfg Interface WEB_B ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 2 135.51.05.22 321.654.987.111 Monitored circuits: vbgghdfgdfg Interface WEB_C ggggggggg Agggggg VRID 145 State: backup XXXXXXXXXXXX Effective Priority: 200 07:09:56:04:0t:ef Primary address: 19.51.205.20 Next advertisement: 0 Number addresses: 3 135.51.05.22 123.456.789.001 321.654.987.111 Monitored circuits: vbgghdfgdfg #### C:\test>junk1 A, WEB_A, 145, Master, 194.551.205.250, 1, 135.51.045.242 A, WEB_B, 145, backup, 19.51.205.20, 2, 135.51.05.22, 321.654.987.111 A, WEB_C, 145, backup, 19.51.205.20, 3, 135.51.05.22, 123.456.789.001, 321.654.987.111 B, WEB_A, 145, Master, 194.551.205.250, 1, 135.51.045.242 B, WEB_B, 145, backup, 19.51.205.20, 2, 135.51.05.22, 321.654.987.111 B, WEB_C, 145, backup, 19.51.205.20, 3, 135.51.05.22, 123.456.789.001, 321.654.987.111