First of all, you're only using the
/g flag, which will interpret your expressions literally and do interpolation. So you end up with this:
s/quotemeta('[')/quotemeta('x')/g;
Which presumably (if it were valid) would match the text "quotemeta'
['", putting '
[' into $1. Try doing this:
s/\Q$array1{$count}\E/$array2{$count}/g;
Or, if each array element simply has one character apiece (as you suggest), forego the loop entirely and use
tr:
$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"