I believe that even though this guard ends up being static, perl can't know this at compile time because of the interpolation of `$keys`.  Perhaps it's worth making both `$guard` and `$matches` regexes right after you build `$keys`