use strict; use warnings; my $echo = "ECHO"; my ($dffname, $listname) = @ARGV; my $fh; my $key=undef; # read key/val lists open $fh, '<', $dffname or die "$dffname $!"; my %lijst = map { chomp; (split /\t/)[1,0] } <$fh>; close $fh; foreach $key (sort keys %lijst) { print "The value associated with key $key is $lijst{$key}\n";} # readfile list open $fh, '<', $listname or die "$listname $!"; my @listfiles = <$fh>; chomp @listfiles; close $fh; for my $file (@listfiles) { # read original file open $fh, '<', $file or die "$file $!"; local $/; my $content = <$fh>; close $fh; # modify content while( my ($key, $val) = each %lijst ) { next unless $val == 1; $content =~ s/^$key$/$echo/gms; $content =~ s/$echo/$key/; } # write modified file open $fh, '>', "$file.out" or die "$file.out $!"; print $fh $content } #### $content =~ s/^$key$/$echo/gms; $content =~ s/$echo/$key/;