You can use UUencoding, perl supports it natively (= without any modules). It can wrap nicely in your source code, too: the line lengths in UUencoded strings are limited.
print unpack 'u*', '92G5S="!!;F]T:&5R(%!E<FP@2&%C:V5R+```';

You can use perl to produce the UUE string, from a binary file, for example.

print pack 'u*', $binstring;

Likewise, you can use a hex string. It doesn't wrap nicely, not without extra measures anyway, and it's longer than UUE: 2x versus 4/3x increase in size.

print pack 'H*', '4A75737420416E6F74686572205065726C204861636B65722C';
Generating such a string can again be done in Perl.
print unpack 'H*', $binstring;
Note that, compared to UUE, the meaning of packand unpack are swapped: in hex, raw/binary is packed, hex text is unpacked. OTOH, UUE is packed, the raw original is unpacked.

In reply to Re: how to store binary string? by bart
in thread how to store binary string? by redss

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.