#!/usr/bin/perl my $start = '/home/moron/ac5'; Init(); Traverse( $start ); close (my $sfh=$_{ FH }{ SUMMARY }); sub Traverse { my $dir = shift; opendir my $dh, $dir or die "$! while opening $dir"; for my $file ( grep !/^\./, readdir $dh ) { my $full = "$dir/$file"; if ( -d $full ) { Traverse( $full ); } else { Process( $full ); } } closedir $dh or die "$! while closing $dir"; } sub Process { my $file = shift; my $itref = $_{ IT }; my $found = 0; open my $fh, "<$file" or die "$! while opening $file"; while( <$fh> ) { KEY: for my $srch ( keys %$itref ) { if ( SmartSearch( $srch ) ) { print join( '|', ( $file, $., $_ ) ) . "\n"; $found++; last KEY; } } } close $fh or die "$! when closing $file"; if ( $found ) { my $sfh = $_{ FH }{ SUMMARY }; print $sfh "$file|$found\n"; } } sub SmartSearch { my $srch = shift; # and this is where I am stuck, except for some horrible ideas of iterating through the combinations of cases such as exception in front, exception behind, exception alone on the line } sub Init { $_{ IT }{ ALPHA } = 1; $_{ IT }{ BETA } = 1; $_{ IT }{ GAMMA } = 1; open my $sfh, ">SummaryFile.dat"; $_{ FH }{ SUMMARY } = $sfh; $_{ EXC }{ ALPHA }{ '_ALPHA' } = 1; $_{ EXC }{ ALPHA }{ '#ALPHA' } = 1; $_{ EXC }{ ALPHA }{ 'CAW5 ALPHA' } = 1; }