Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:

I need to be able to open a file in binary mode, then search for a specific string of hexadecimal numbers and replace each character with the hexadecimal character 00. The problem I have is that the string I'm searching for will vary in length and content. Each string will start with the same characters (31,33,39,37) and end with the same character (00). However, each string will contain different characters between the beginning (31,33,39,37) and end (00) as well as being different lengths. This is what the code looks like right now:

How can I tell the program to start replacing characters when it encounters 1397 and then stop replacing characters when it encounters a 0? Is there some sort of wildcard character that I can use that will replace every character it encounters?

The line-processing approach above unfortunately does almost exactly the opposite of what you want, unless I'm tireder than I thought. The problem you're going to have is that you aren't (or at least, you haven't mentioned that you are) reading a record-based file, so no matter what size chunk you read in, unless you read the whole file into a scalar, you run the risk that you'll have a string that begins in one read and ends in another. There are a few ways to deal with this, but for the moment I'm going to pretend you can read the whole file in as a single string, because it will make my life easier. In that case, this should do roughly what you want (and precisely what you specified):