my $tail_length = 10; sub contains_polytail { my $file = shift; open my $fh, "<$file" or die "Couldn't open $file: $!"; ## only read the last 10 + 2 bytes seek $fh, -( $tail_length + 2), 2; my $tail = do { local $/; <$fh> }; ## ignore newlines and ^M's $tail =~ s/[\r\n]//g; return ($tail =~ /[AN]{$tail_length}$/); } print contains_polytail('test.dna') ? "yes\n" : "no\n";