use keys instead of each to workaround perl bug

in perl before 5.14 each may panic with: attempt to copy freed scalar
Merge pull request #506 from trinitum/replace-each-with-keys

use keys instead of each to workaround bug in perl