use 5.010; use Tie::ArrayAsHash 'aeach'; my %hash = qw( a foo b bar c baz ); my @array = qw( foo bar baz ); while (my ($key, $value) = aeach %hash) { say "HASH $key => $value"; } while (my ($idx, $value) = aeach @array) { say "ARRAY $idx => $value"; }