in reply to pattern matching

You should look at the /g modifier of the pattern matching operators:
while(m/.../g){ ...# Every match }


BTW: What do you mean by (\d+){1,400}? It's something like "One or more digit, 1-400 times..", which makes the {1,400} somewhat redundant.