Yep, it works with Lmod (https://lmod.readthedocs.io) and environment modules (https://modules.sourceforge.net). See the tutorial on setting up modules for what the integration looks like:
* https://spack-tutorial.readthedocs.io/en/latest/tutorial_mod...
AFAIK environment modules are implemented in TCL, not perl. The original was in C with an embedded TCL interpreter, but when CEA revived the project w/version 4 in 2017, it was all in TCL.