in reply to Problem with a replacement

What am I doing wrong?
  1. Not using strictures (use strict; use warnings;)
  2. Not using a lexical file handle
  3. Not using three parameter open
  4. Not checking the result from open
  5. Not indenting code
  6. Not providing runnable sample code that demonstrates your problem
  7. Not showing actual output from your sample code
  8. Not showing expected output from your sample code

There may be logic or other errors in your code too, but it's not clear what you are trying to do to be sure where such errors may be. However, by the time you've cleaned up all the items on the list above you'll probably have cleaned up your other error to.

True laziness is hard work