Are you talking about shrinking in place, so you don't have the overhead of having the compressed and uncompressed strings in memory at the same time?
my $str =<<'EOS'; There once was a man from Nantucket, Who kept all his cash in a bucket. His daughter, named Nan, Ran off with a man. And as for the bucket, Nantucket. EOS sub shrink_in_place { for (my $i=0; $i<length($_[0]); $i+=7) { for (substr($_[0], $i, 8)) { $_ = pack('B*', grep s/.(.{7})/$1/g, unpack('B*', $_)); } } } sub grow_in_place { for (my $i=0; $i<length($_[0]); $i+=8) { for (substr($_[0], $i, 7)) { $_ = pack('B*', grep s/(.{7})/0$1/g, unpack('B*', $_)); } } } print "$str"; printf "Length is %d\n", length($str); shrink_in_place($str); printf "Shrunk length is %d\n", length($str); grow_in_place($str); print "Restored: $str";

Caution: Contents may have been coded under pressure.

In reply to Re^5: Efficient 7bit compression by Roy Johnson
in thread Efficient 7bit compression by Limbic~Region

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.