use strict; use warnings; #### my %table = ( "\x00" => "\x17", "\x17" => "\x00", ... ); my $re = join '|', map quotemeta, keys %table; # open in and out files... # and then substitute: $str =~ s/($re)/$table{$1}/g