in reply to incorrect syntax when using mkpath

mkpath is not a command on your system, but a perl function:
use File::Path qw(mkpath); ... mkpath("M1_fa_$W/M1_${W}__comptage_${C}_${I}_first_action"); ...

If you want to use system for some other reason (usually not recommended), the unix equivalent is mkdir -p.

(BTW you might want to use sprintf to create the file names, that could be much easier than your interpolation).