Recursion assumes that data structure consists of hashes and arrays only, and array elements are not references,
use strict;
use warnings;
use Data::Dumper;
my %h;
@h{ 1..5 } = (
{ 'item3' => { 'floors' => [ 'a', 'b', 'c' ] } },
{ 'item1' => [ 'special' ] },
{ 'item2' => {
'books' => { 'topics' => [ 'epics' ] },
'sports' => [ 'tennis' ]
}},
{ 'item5' => { 'groups' => { 'teams' => [ 'x', 'y' ] } } },
{ 'offers' => { 'list' => [ 'bags' ] } },
);
print Dumper [ arrvals(\%h) ];
sub arrvals {
my ($ref) = @_;
return ref($ref) eq "ARRAY"
? @$ref
: map arrvals($_), values %$ref;
}