#!/usr/bin/perl use warnings; use strict; #### my $infiles = '/path/to/RETAKC*.txt'; my $outpath = '/another/path/'; use File::Basename 'basename'; #### my %substitute = ( '0000J' => '000-1', # . . . ); my $regex = qr/(${\join '|', keys %substitute})/; #### for my $file (glob $infiles) { open my $in, '<', $file or warn $! and next; open my $out, '>', $outpath.basename($file) or warn $! and next; while (<$in>) { s/$regex/$substitute{$1}/g; print $out $_; } }