in reply to Searching and Replacing

you should use s///

like this

 s/$pattern/$replacement/;
that would replace all instances of $pattern. but the rest looks good to me. (this replaces the While Input code)


 Update use s///g to replace all instances. Thanks runrig for the correction.