Refactor some code from internals of Dumpperl().