$string_filename = 'sequence.txt'; open(FILE, $string_filename) || die("Couldn't read file $string_filename\n"); $motif_filename = 'motif.txt'; open(MOTIF, $motif_filename) || die("Couldn't read file $motif_filename\n"); local $/ = "\n>"; while (my $seq = ) { chomp $seq; $seq =~ s/^>*.+\n//; $seq =~ s/\n//g; $R = length $seq; $motif = ; chomp $motif; $motif =~ s/^>*.+\n//; $motif =~ s/\n//g; if ( $seq =~ /$motif/ ) { ## insert actual binding site $M = $'; $W = length $M; if ( $seq =~ /[A-Z]/) { ## exon start $K = $`; $Z = length $K; $x = $W + $Z - $R; print "\n\ the distance is the following: $x\n\n"; } else { print "\n\ I couldn't find the start codon.\n\n"; } } else { print "\n\ I couldn't find the binding site.\n\n"; } } close MOTIF; close FILE; exit;