I have tried iterating with foreach and the hash itself
foreach (keys $hash){
print $_ . "\n";
}
So far so good ...
Given the code you OPed, it's hard to imagine this would have done anything "good" unless $hash.was actually a hash reference. If this was the case, please be aware of this from the latest Perl documentation:
Starting with Perl 5.14, an experimental feature allowed keys to take a scalar expression. This experiment has been deemed unsuccessful, and was removed as of Perl 5.24.
This experimental ex-feature was also associated with values, each, push, pop and friends.
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |