#!/usr/bin/perl $filename = "sample"; open (TEXT, "sample.txt")||die"Cannot"; $line = " "; $count = 0; for $n (5..50) { $re = qr /[CAGT]{$n}/; $regexes[$n-5] = $re; } NEXTLINE: while ($count < 1000) { $line = ; $count++; foreach my $value (@regexes) { $start = 0; while ($line =~ /$value/g) { $endline = $'; $match = $&; $revmatch = reverse($match); $revmatch =~ tr/CAGT/GTCA/; if ($endline =~ /^([CAGT]{0,15})($revmatch)/) { $start = 1; $palindrome = $match . "*" . $1 . "*" . $2; $palhash{$palindrome}++; } } if ($start == 0) { goto NEXTLINE; } } } open my $out, ">/DIR/results.txt"; close TEXT; while(($key, $value) = each (%palhash)) { print $out "$key => $value\n"; } exit;