in reply to trouble matching

As pointed out in sk's reply, you should not be nesting your while loops. And you certainly do not need more than two while loops.

You seem to have an idea already that some files contain "configuration" or "instruction" data (list of patter/replace pairs, list of text files to operate on), so read each of those files into a hash or array, as appropriate. Then figure out how to actually do all the work in a single pass over the data files. Maybe something like this:

use strict; use warnings; # ... initialize some path and file names ... # Open file with search items my %terms; open(FILE,"<$ssearch") or die "$ssearch: $!"; while (<FILE>) { # use $_ chomp; my ( $term, $newterm ) = split /-/; $terms{$term} = $newterm; } # Open file with list of files to be searched open(FILE,"<$fsearch") or die "$fsearch: $!"; my @sigfiles = <FILE>; chomp @sigfiles; # loop over the files to be searched for my $file ( @sigfiles ) { open( IFILE, $file ) or die "$file: $!"; open( OFILE, ">$dir/REVISE_$file" or die "$dir/REVISE_$file: $!"; # loop over lines in the file while (<FILE>) { ## at this point, it's hard to tell what you really want to do... ## you can refer to "keys %terms" and "values %terms" and "$terms{$k +ey}" ... } ## do you need to print something to your output that serves as ## some sort of "summary" for each input file? If so, do that here. ## (you probably should simplify/combine your various printf statemen +ts) }
Good luck with that...