s/quotemeta('[')/quotemeta('x')/g; #### s/\Q$array1{$count}\E/$array2{$count}/g; #### $from = join('', @array1); # or set up $from and $to $to = join('', @array2); # to begin with tr/$from/$to/; # e.g. "abc" =~ tr/ab/xy/ ==> "xyc"