#!/usr/bin/perl use strict; my $dir = 'c:/temp/tmp'; # directory to search my @files = glob("$dir/*.txt"); for my $filename (@files){ my $lineno = 0; print "Scanning $filename ..\n"; open IN,'<',$filename or die "Could not open $filename : $!"; my $iface; while (){ ++$lineno; if (/^interface\s+(.*)/){ $iface = $1; } if (/spanning-tree guard/){ print "$filename,$lineno,$iface,$_"; $iface = ''; } } }