(NB: It's not really necessary to post a reeeeealy looooong string to convince us you're dealing with long strings. We're prepared to take your word. Shorter example strings would seem to have been sufficient.)

Insofar as I understand your problem, this is the classic, idiomatic Perlish solution. (I don't know if you really need your  $str1 string transformed also; I do it essentially to support the example.) This approach assumes that  $s1 and  $s2 are always the same length, and also that the null character  \x00 is never a valid part of the  $s1 or  $s2 string.

c:\@Work\Perl\monks>perl -wMstrict -le "my $s1 = '---DAAAGLRG--G--G-P-LT-IGGY'; my $s2 = '...XXXXXXXX..X..X.X.XX.X..X'; print qq{'$s1'}; print qq{'$s2'}; ;; (my $mask = $s1) =~ tr{-\x00-,.-\xff}{\x00\xff}; my $t1 = $s1 & $mask; my $t2 = $s2 & $mask; $t1 =~ tr{\x00}''d; $t2 =~ tr{\x00}''d; ;; print qq{'$t1'}; print qq{'$t2'}; " '---DAAAGLRG--G--G-P-LT-IGGY' '...XXXXXXXX..X..X.X.XX.X..X' 'DAAAGLRGGGPLTIGGY' 'XXXXXXXXXXXXXX..X'

Update: Replaced  s/// with  tr/// in masked character removal step:  $t1 =~ tr{\x00}''d; instead of  $t1 =~ s{ \x00+ }''xmsg;


In reply to Re: How to make this substitutions without splitting the strings? by AnomalousMonk
in thread How to make this substitutions without splitting the strings? by Anonymous Monk

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.