title: Replace multiple hex values
body: <p>I've written the following script because I need to do some cleanup in some files. I have a specific number of hex characters that needs to be changed into another set of hex characters (ie null to space, see below). I've written the following script, my problem is that it only replaces the first occurence and nothing else. </p>
  
  <p>I've tried the /g just like a regular sed pattern but it doesnt work. Is there a way to do this and replace all matches?</p>
  
  <p>(The reason i havent used a <code>$line =~ s/...</code> is because I think its neater and more maintainable that way, and this script will need to be accessed and run on occasion by others who may need to edit the hex values to be replaced). Another reason is because i need to change from 10+ hex values to an equivalent amount, so a huge one liner would be hard to read. Thank you in advance.</p>
  
  <pre><code> #!/usr/bin/perl
  
  
   use strict;
   use warnings;
  
   my $filebase = shift || "testreplace.txt";
   my $filefilter = shift || "testf";
  
   open my $fh1, '&gt;', 'testreplaceout';
  
   # Iterate over file and read lines
   open my $file1, '&lt;', $filebase;
  
   while (my $line = &lt;$file1&gt;)
   {
      chomp($line);
  
      for ($line) {
              s/\x00/\x20/g;
              s/\x31/\x32/g;
      }
  
      print {$fh1} "$line \n";
  
  
   }
  </code></pre>