How 'bout something like the following (granted it can probably be improved upon:
use strict; use warnings; use Text::Wrap; $Text::Wrap::columns = 80; output (q|\e[33mCoruscate\e[0m;\e[37;40m is having trouble with a scri +pt he is working on and therefore makes a trip to \e[32mwww.perlmonks +.org\e[0m;\e[37;40m to seek help|); # Modified print() sub output { my $text = shift; my @removed; my $current_position = 0; while ( $text =~ m!(\\e\[[\d;]+[mK];?)!g ) { push @removed, [pos($text) - length($1), $1]; } $text =~ s!\\e\[[\d;]+[mK];?!!g; my $wrapped = wrap('', '', $text); while ( @removed ) { my $current_element = shift @removed; substr($wrapped,@{$current_element}[0]) = @{$current_element}[1] . substr($wrapped,@{$current_element}[0]); } print $wrapped; }
update:did I mention it could be improved upon. I realized what hv noticed about 20 min after I left for lunch. I admit this code is therefore pretty broken. Thanks hv for the heads up anyhow.

update2: As for tye's solution above WOW!! I tried to fix my mistakes, but after figuring out how his worked I was humbled (need I say more).

-enlil


In reply to Re: Wrap while ignoring certain sequences by Enlil
in thread Wrap while ignoring certain sequences by Coruscate

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.