in reply to matching every occurrence of a regex

You are making this more difficult than it is.

$string =~ m/\s(\d+)\s/; $nposition = $1;

If the sequences are in a file, you can just open the file and read through every line with a while loop. If you find a match, you can put it in an array.