in reply to mkdir in loop - overwrite danger?

I am curious as to why you want to move the desired files? What purpose does that serve? Perhaps that is because there are a lot of "junk files"? I don't know.

A simple database of these relevant file names could be just what you need? I would need to know more about what the usage is.

A serious thing to consider is what happens when some file name is deleted as *text and how that affects your directory structure? Your program should have the property that it produces a valid result again and again even if some "line" is missing from the next run...

As an extra note...there is no need at all to use these $1, $2,$3 variables in almost all cases in Perl. There are of course exceptions...

my ($seq,$nr,...) =( /prefix_(\d+)_(\d+)_(\w+)(_)(\w+)(_)(\w+)(\.)(\w+)/)[1,2,3...];
This is called "array slice" and is powerful.

I figure that your regex is flawed. Do not use () to capture any thing that is not needed. These $1,$2,$3 variables are expensive. This \w+ then followed by "_" can also be "expensive". The underscore is part of the \w character set, a-zA-Z0-9_-.