in reply to Complicated pattern match

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)