I wonder if tr might help you. Particularly, the c flag complements the characters specified so, you can get rid of anything that isn't a newline (0x0a) and the range of printable characters from space (0x20) through ~ (0x7e). Also include return (0x0d) if on Windows.

$ perl -le ' > $str = qq{\x00\x03abc xyz\n\x00\x00\x0912 34 56\x05\n}; > print for map sprintf( q{0x%02x}, ord ), split m{}, $str; > print q{-} x 20; > $str =~ tr{\x0a\x20-\x7e}{}cd; > print for map sprintf( q{0x%02x}, ord ), split m{}, $str;' 0x00 0x03 0x61 0x62 0x63 0x20 0x78 0x79 0x7a 0x0a 0x00 0x00 0x09 0x31 0x32 0x20 0x33 0x34 0x20 0x35 0x36 0x05 0x0a -------------------- 0x61 0x62 0x63 0x20 0x78 0x79 0x7a 0x0a 0x31 0x32 0x20 0x33 0x34 0x20 0x35 0x36 0x0a $

I hope this is helpful.

Cheers,

JohnGG

Update: Fixed typo.


In reply to Re: keeping spaces by johngg
in thread keeping spaces by Spooky

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.