in reply to Replace and substitur in same file
So how does your current code fail?
If you add strictures (use strict; use warnings;) do you get information that may help solve your problem?