Here is another approach (again, for one pair of words, so extending would be an exercise for the reader):

use strict; use warnings; my $str1 = q{CHARLIE ROOT}; my $str2 = q{HARRY NODE}; my $output = process( $str1, $str2 ) . q{ } . process( $str2, $str1 ); print $output, qq{\n}; sub process { my ( $word1, $word2 ) = @_; my @letters_to_remove = grep{ ! m/\s+/; } split //, $word2; my $remove_str = join q{}, q{[}, @letters_to_remove, q{]}; my $result = $word1; $result =~ s/$remove_str//g; return $result; }

Output:

CLI T Y ND

In this code, a character group is constructed on the fly, and a substitution operation replaces each member globally in the string with nothing, removing the character. (The string is not as efficient as it could be, since it may contain repeated characters, but this was off-the-cuff code, so there we are.)

Hope that helps-if not in usefulness, then at least in seeing different possible approaches to the same problem.


In reply to Re^2: Mostly Harmless by atcroft
in thread Mostly Harmless by emdub

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.