You can simplify this:
my $Are = '^(.*)' . join('(.*)', @A) . '(.*)$';
Like so:
my $Are = join '(.*)', '^', @A, '$';

I'd also use a nongreedy .*? there instead.

You provided a code base I liked quite a bit and couldn't stop tinkering with though - that temporary @A was annoying. :) Eventually it occured to me I could just capture the matches from $A as well:

my $Are = join '(.*?)', '^', (map "($_)", $A =~ /(.)/sg), '$';
Now it all goes in a single array where every odd element is guaranteed to be one character long, while every even element may have any length incl zero. With that in mind, I wrote a cleanup loop and eventually arrived at this:
#!/usr/bin/perl -w use strict; my $A = 'ATGGAGTCGACGAATTTGAAGAAT'; my $B = 'xxxxxxATGGAGyxxxTCGAzxxxxCGAATTTGAAxxwGAAT'; my $Are = join '(.*?)', '^', (map "($_)", $A =~ /(.)/sg), '$'; (my @introns = $B =~ m/$Are/) or die "There was no possible way to match the input."; my @seq; while(@introns) { my $match = shift @introns; if(@seq and not $match) { $seq[-1] .= shift @introns || ''; next; } push @seq, $match; } print "$A\n@seq\n"; __END__ ATGGAGTCGACGAATTTGAAGAAT xxxxxx ATGGAG yxxx TCGA zxxxx CGAATTTGAA xxw GAAT

Update: hrm.. it doesn't work so well anymore once you substitute "real" sequences for the dummy characters in $B..

ATGGAGTCGACGAATTTGAAGAAT
ATGGAG A T GGAGT CGA T CGAA G T CACCGAA TT T GAA TTT GAAT

I suspect nearly the same is true for theorbtwo's code due to the nature of pattern matching.

Makeshifts last the longest.


In reply to Re^2: Complicated pattern match by Aristotle
in thread Complicated pattern match by dr_jgbn

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.