my @motifs; while (my $motif = ) { ... push @motifs, $motif; } while (my $seq = ) { ... for my $motif (@motifs) { if ( $seq =~ /$motif/ ) { ... } ... } }