If I may make a minor comment, I don't think it is a good idea to call a scalar $sub. When I was reading the code my eye missed the '$' and I thought that you were doing something unusual to a subroutine.
If you just called the scalar $subst the initial confusion would go away.