#!/usr/bin/perl use warnings; use strict; $/ = "#"; while () { next if $. == 1; # Skipt the empty "first" record; my @lines = split /\n/; my ($vlan, $ifconfig) = (0, 0); for (@lines) { if (/^hostname/) { print "$_\n"; } elsif (/^vlan/) { $vlan++ for m/\S+/g; $vlan -= 3; } elsif (/^ifconfig/) { $ifconfig++ for m/\S+/g; $ifconfig -= 3; } } print "vlan $vlan\nifconfig $ifconfig\n"; print "WRONG!!!\n" if $vlan != $ifconfig; }