Received so much help with the last question (which seems to be functioning great, btw.. thanks all)... thought I&#39;d try again.  ;)<div><br></div><div>Have a script that was recently migrated to Perl from shell/bash, and am wondering if there&#39;s an easy way in Perl to do the following-</div>
<div><br></div><div>File(s) being modified are hex, and look something like:</div><div>---x---</div><div>...</div><div>08 00 00 00 FF FF FF FF FF FF FF FF 1B 00 00 00 02 01 10 00 28 01 00 00 09 00 00 00 FF FF FF FF FF FF FF FF 1C 00 00 00 14 00 14 00 0D 00 00 00 00 00 0D 00 18 00 00 00 11 00 00 00 FF FF FF FF 08 00 00 05 02 0E 00 00 18 00 00 00 0E 00 00 00 FF FF FF FF 08 00 00 1C 00 00 00 FF 18 00 00 00 09 00 00 00 FF FF FF FF 08 00 00 11 10 00 00 00 18 00 00 00 0F 00 00 00 FF FF FF FF 08 00 00 01 11 02 02 01 18 00 00 00 03 00 00 00 FF FF FF FF 08 00 00 01 05 00 08 01 18 00 00 00 10 00 00 00 FF FF FF FF 08 00 00 05 01 0F 00 00 18 00 00 00 05 00 00 00 FF FF FF FF 08 00 00 05 01 0F 00 00 18 00 00 </div>
<div>...</div><div>---x---</div><div>File(s) contain several occurrences of &quot;08 00 00 1c ## ## ## ##&quot; or more appropriately for this list: &quot;08\s00\s00\s1C\s\d\d\s\d\d\s\d\d\s\d\d&quot;</div><div><br></div><div>
Now on to the good stuff...  I would like to replace the ## ## ## ## with my chosen colors, that are being provided by vars... Example:</div><div>colorChange1=&quot;FF 00 00 FF&quot;</div><div>colorChange2=&quot;FF FF 00 FF&quot;</div>
<div>colorChange3=&quot;FF 00 FF FF&quot;</div><div>...</div><div><br></div><div>I&#39;m wondering how it might be possible, to replace the FIRST occurrence (in the file, NOT in a line) of &quot;08 00 00 1C ## ## ## ##&quot; with &quot;08 00 00 1C $colorChange1&quot;, the second with &quot;08 00 00 1C $colorChange2&quot;, etc.</div>
<div><br></div><div>More info:</div><div>--Script modifies files to theme them, in this case, I&#39;m taking a BINARY (compiled XML) file, converting it to HEX via xxd, and then changing the text color for a theme via substitution.</div>
<div>--I originally thought it could be done similar to what sed does... with s|(08\s00\s00\s1C)\s\d\d\s\d\d\s\d\d\s\d\d|$1$colorChange1|1  (note last digit...), but testing has shown that this doesn&#39;t work as expected.</div>
<div>--Not really related, but in the binary, the colors are actually backwards, so color - FF AB CD EF becomes binary - EF CD AB FF, but that&#39;s an easy change.</div><div>--CURRENTLY in my script, I&#39;m doing this via a sub, passing an array of the colors, the file, and the file location (directory), and pulling the file, making the changes, and saving it back out via loop... BUT, because I couldn&#39;t figure out how to just do the multiple replaces... I cheated and made template files that contain &quot;08 00 00 1C 11 11 11 11&quot; and &quot;08 00 00 1C 22 22 22 22&quot;, so when I iterate through the loop, I just change like so:</div>
<div>for ( $i = 1 ; $i &lt;= $COUNT ; $i++ ) {</div><div>...</div><div>    $line =~ s|08\s00\s00\s1c\s$i$i\s$i$i\s$i$i\s$i$i\s|08 00 00 1c $array_ref[$i]|;</div><div>...</div><div>}</div><div><br></div><div>Code works, but I&#39;d much rather be able to pull native files straight out of the .zip, and change them that way... :P</div>
<div><br></div><div>Anyway, again, if there are specifics I missed, happy to provide them.  </div><div>I keep thinking there should be an easy way to do this... but my google-fu is failing me.. </div><div><br></div><div>Thanks again for the help with the previous problem, and in advance for any assistance on this one.  :)</div>
<div>At the very least, I guess I can provide some chatter to the group.</div><div><br></div><div>-John (sephtin @gmail)</div>