I think you need to say more about what you need to do with the first and last characters. Can you ignore 500-char ranges spanning the > marks? Are you looking for some literal first character? If the answers are yes, something like this should go pretty quickly, using a regex to go through the buffer one character at a time:
$/ = ">";
while (my $line = <>) {
while ($line =~ m/x(?=.{498}(.))/gs) {
my $from_x_500_chars = $1;
}
}
If you do try different methods suggested, it would be nice if you posted a summary of results.