. And don't nest your subroutines
like that unless you know what you're doing and want to
create closures on purpose. You might be using
(I can't absolutely tell), but you're not using warnings,
because you have a problem with that $key variable in the
foreach loop not staying shared (its declared in a sub in an outer
scope but being used in a sub in an inner scops).