terminal – Automate the filing of files in folders according to the beginning of the file name?

You're looking to quickly organize a whole load (talking about several thousand) of files into subfolders, and the files are grouped into three separate files (left audio, right audio, video). Not really experienced in the terminal, but already in Automator.

Example:

00015_A01.mxf
00015_A02.mxf
00015.mxf
00016_A01.mxf
00016_A02.mxf
00016.mxf

I want to automate it so that the searcher looks for the files with the corresponding first characters and places them in a subfolder (preferably with the name of this file, but I managed a workaround for that.)

So the result would be:

[00015] (folder)
00015_A01.mxf
00015_A02.mxf
00015.mxf

[00016] (folder)
00016_A01.mxf
00016_A02.mxf
00016.mxf

Ideas? I've checked here but the answers were a little on my head …

Any help really appreciated people!