If the file actually contains text that consists entirely of hexadecimal digit characters -- e.g. a file is ten bytes long (plus LF or CRLF line-termination, perhaps), and contains just characters like this:
B58013A7FF
then one plan would be to group the string of hex digits into pairs then replace the ones that are "A7" with "00" and rebuild the string -- something like this would do it:
while (<DATA>) { chomp; my $out = ''; while ( /([0-9a-f]{2})/gi ) { $out .= ( uc($1) eq 'A7' ) ? "00" : $1; } print "$out\n"; } __DATA__ b58013A7FF
On the other hand, if you want to treat the file as binary data, and any single byte in the file that happens to have the value 0xA7 (i.e. 167. decimal, 10100111 binary) should be replaced by a null byte, then the plan would be read some number of raw bytes into a scalar, replace 0xA7 with 0x00 throughout, and write the result -- something like this (set up as a stdin > stdout filter):
binmode STDIN; binmode STDOUT; $/ = \8192; # set "input record separator" to 8KB per read while (<>) { tr/\xa7/\x00/; print; }
In case you don't know about stdin > stdout filters, it's just a matter of running the script using redirection from some file for input and redirection to some other file for output, like this:
script.pl < input.file > output.file

In reply to Re: How to open a file in hexadecimal form? by graff
in thread How to open a file in hexadecimal form? by pccode

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.