$/ = ">"; while (my $line = <>) { while ($line =~ m/x(?=.{498}(.))/gs) { my $from_x_500_chars = $1; } }