Ok, figured out a sort-of kludge... turns out I don't really need perl, I can work around it in other ways
code:
@for /D %%d in (*) do @for %%f in (AI_*.txt) do @for /F "usebackq tokens=2* delims=_" %%g in ('%%f') do @copy %%f .\%%d\%%d_%%g_%%h
@for /D %%D in (*) do @for %%F in (.\%%D\*.txt_) do @rename .\%%D\%%~nF.txt_ %%~nF.txt
Same procedure as before, takes all files matching AI_*.txt in a directory, and copies it to all subdirectories, taking off the 'AI_' and replacing it with '{subdirname}_'.
Link in first post has been updated.