See also this thread for a very similar, though not identical, problem. Also, Hello! to your perl teacher.

#! /usr/bin/perl sub ano1 { my ($str1, $str2) = @_; my ($last) = $str2 =~ /.*(\w)/; tr/\0-/-=/, s/=(?=\W*(\w?))/ $1 || $last /ge for my $answer = $str1 =~ tr/A-Z/\0/r ^ $str2; $answer; } sub ano2 { my ($x, $y) = @_; $y &= ($y =~ tr/-\0-\377/\0\377/r) | ($x =~ tr/-\0-\377/\377\0/r); $y =~ s/(\0+)(.)/$2 x (1 + length $1)/eg; $y =~ s/(.)(\0+)$/$1 x (1 + length $2)/er; } chomp (our ($str1, $str2) = <DATA>); use Benchmark 'cmpthese'; cmpthese -5, { ano1 => q( ano1 $str1, $str2 ), ano2 => q( ano2 $str1, $str2 ), }; __DATA__ MCCAALAPPMAATVGPESIWLWIGTIGMTLGTLYFVGRGRGVRDRKMQEFYIITIFITTIAAAMYFAMAT +GFGVT-------------EVMVG----DE---ALTIYWARYADWLFTTPLLLLDLSLLAGANRN----T +IATLIG-LDVFMIG---T---GAIAALSST-PGTRIAWWAIST--GALL--ALLYVLVGTLSENARNRA +PEVA--SLFGRLRNLVIALWFLYPVVWILGT---EGTFGILP--LYWETAAFMVLDLSAKVGFGVILLQ +SRSVLERVATPTAAPT --OOOOOOOOOOOOOOOOMMMMMMMMMMMMMMMMMMMMMIIIIIIIIIIMMMMMMMMMMMMMMMMMMMMM +OOOOO-------------OOOOO----OO---OOOOMMMMMMMMMMMMMMMMMMMMMIIIIIII----M +MMMMMM-MMMMMMM---M---MMMMMMOOO-OOOOMMMMMMMM--MMMM--MMMMMMMMMMIIIIIIII +IIII--IIIIMMMMMMMMMMMMMMMMMMMMO---OOO-OOOO--OOOMMMMMMMMMMMMMMMMMMMMMI +IIIIIIIIIIII----


In reply to Re: More efficient way for this pattern match? by Anonymous Monk
in thread More efficient way for this pattern match? 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.