Here is a sample of what a cleaner (in my opinion) version of your code should look like:
#...
my @lines = ();
open my $inFile, '<', 'svrrp.txt' or die "Couldn't open svrrp.txt: $!"
+;
my $currIface = "";
while (<$inFile>) {
chomp;
if (my $iface = ($_ =~ /^Interface\s(\w+)$/) {
processlines($currIface, @lines);
$currIface = $iface;
@lines = ();
}
push @lines, $_;
}
processlines($currIface, $lines); # to process last interface block
#...
sub processlines() {
my $iface = shift;
return unless $iface;
# declare any vars
foreach (@_) {
# do your pattern matching here
}
# print your findings
}
You can expand on this to make it suit you.
-imran |