It's almost certainly to do with running the regex on both the key and the value of the hash. Probably some of the values of a packlist object (returned by ExtUtils::Installed->new->packlist()) are undefined... Is there a function of that packlist that returns what you want, rather than dumping the whole object hash?
that's silly. Instead, try something like
inside the grep.
But know what you want to run the substitution on first (and other people have suggested this, I know) and do it only on those...