I liked your problem: If I understand your problem, the sequences in A must all be matched in order of appearance in B without repeating the sequence in A or in B. You may need to sequence through a possible 24 times, but I leave that up to you as you will see how to accomplish this. Try uncommenting the second data and you will see what I mean: My solution=)
#!/perl/bin/perl use strict; my @chem; my %seqB; my ($key, $value,$data, $pos, $x, $num, $seq); my $DNA = "xxxxxxATGGAGyxxxTCGAzxxxxCGAATTTGAAxxwGAAT"; #my $DNA = "CGATAAATGGAGTGACTCGAGATCGCGAATTTGCCAAACACGAAT"; while(<DATA>){ chomp; @chem = split //; } my $seq_prev =''; for(1..10){ $num = @chem; $num--; for (0..$num){ $key = join '', @chem[0..$_]; if($DNA =~ /($key)/i){ $seq = $`; $data = $key; $pos=$_+1; } #first sequence in A found } #remove the matched squence from future possible matches splice @chem, 0, $pos; #show the results my $chem= join '', @chem; print "FIRST SEQ MATCH FOUND: $seq_prev|< $data >|$chem\n"; print "\nDNA(B)- BEFORE < $data >: $seq"; $seq_prev = $data.$seq_prev; $seqB{$data} = $seq; #remove the matched DNA B pattern matched data $DNA =~ s/$seq$data//; # exit(0) if $DNA eq ''; #if you wanted to match more than 4 } print "AS A HASH TABLE KEY:VALUE PAIRS\n"; foreach (keys %seqB){ print "$_ = $seqB{$_}\n"; } __DATA__ ATGGAGTCGACGAATTTGAAGAAT
It gives you what you want for both the data you provided and for any generic data sets. JamesNC :0)

In reply to Re: Complicated pattern match by JamesNC
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.