Here's a solution using Bioperl:
#!/usr/bin/perl -w
use strict;
use Bio::SeqIO;
my @files = <*.seq>;
my $pattern = '([AN]*)';
foreach my $file (@files) {
my $seqio = Bio::SeqIO->new( -file => $file );
while ( my $seqobj = $seqio->next_seq() ) {
my $raw_seq = $seqobj->seq();
my @length_of_matches;
while ( $raw_seq =~ /$pattern/og ) {
push @length_of_matches, length $1;
}
@length_of_matches = sort { $b <=> $a } @length_of_matches;
print $length_of_matches[ 0 ], ' ', $file, "\n";
}
}
Using Bioperl for easy scripts likes this is a good idea, because it allows you to very easily port your program to almost any sequence file format known to man.