QUOTE(dstorey @ 29 Sep, 2009 - 09:28 PM)

Ok so the idea here is that i'm searching a string ( DNA ) for restriction cuts. ( I'm actually searching two strings and then comparing them and putting them in three classes : both sequences lack the search sequence , one sequence has a cut site , both sequences have a cut site.
For some reason the string isn't matching when i know that a cut site exists any suggestions?
Can you reduce the problem to a minimal program which both runs and demonstrates the problem you're having? Doing so, along with telling us what output you want to result, will make it much easier for us to identify the cause of the problem. While I could easily turn the fragment of code you posted into a complete runnable program, I would still only be guessing at what input it should be given or what output it should produce, so I'd be likely to end up "fixing" something that wasn't broken in the first place.
I can offer some stylistic revisions from what you've provided, though.

My assumptions here are that:
- You have two input strings, $seq1 and $seq2.
- You have a list of target sequences, @reseq.
- Each entry in @reseq has a corresponding entry in @rename.
- The desired output is a list of the entries in @rename along with an indication for each of whether the corresponding @reseq entry appears in neither, one, or both of $seq1 and $seq2.
Given that those assumptions are correct, the following code should do what you want:
CODE
my @rename_tmp = @rename;
my %name_map;
my %cuts;
for my $reseq (@reseq) {
$name_map{$reseq} = shift @rename_tmp;
# The following line is solely to protect against
# duplicate sequences in @reseq. If all @reseq
# entries will always be unique, you don't need it.
next if exists $cuts{$reseq};
$cuts{$reseq}++ if $seq1 =~ /$reseq/;
$cuts{$reseq}++ if $seq2 =~ /$reseq/;
}
for my $reseq (@reseq) {
print $name_map{$reseq};
if (!$cuts{$reseq}) {
print " cuts in neither sequence.\n";
} elsif ($cuts{$reseq} == 1) {
print " polymorphic cutter.\n";
} else {
print " cuts both sequences.\n";
}
}
Also note that I only used separate processing and output loops because that was what you'd done in your original code. If you don't need to do anything else between those stages, this can be reduced to a single loop:
CODE
my @rename_tmp = @rename;
for my $reseq (@reseq) {
my $cuts;
$cuts++ if $seq1 =~ /$reseq/;
$cuts++ if $seq2 =~ /$reseq/;
print shift @rename_tmp;
if (!$cuts) {
print " cuts in neither sequence.\n";
} elsif ($cuts == 1) {
print " polymorphic cutter.\n";
} else {
print " cuts both sequences.\n";
}
}