I'm reasonably competent in perl regex substitutions, but I'm getting kind of rusty and this is something I don't usually do. It's to escape an & character for XML but prevent replacing &'s in already-escaped characters. It seems to work fine except it deletes or replaces the character to the right of it. What am I missing?

```
$str =~ s/&[^amp;|lt;|gt;|quot;|#39;]/&amp;/g;

```