opendir( my $dir, $dirname ); my @in = grep { /^[^.]/ && -f "$dirname/$_" } readdir( $dir ); closedir $dir; for my $file (@in) { open( my $infile, '<', "$dirname/$file" ) or next; open( my $outfile, '>', "$outdirname/$file" ) or die "can't open file output/$file: $!"; while ( my $line = <$infile> ) { $line =~ s/rotate\(-180/rotate\(-0/g; if ( $line =~ m/$target/ ) { for my $key (keys %stroke_width_hash) { $line =~ s/$key/$stroke_width_hash{$key}/g; } } print $outfile $line; } close $outfile; close $infile; }