my @stack; push @stack, [ 1 .. 10 ]; # an array push @stack, { one => 1, two => 2 }; # a hash push @stack, 'a scalar'; push @stack, Some::Object->new; my ($scalar, @array, %hash, $obj); while (my $x = pop @stack) { if (my $type = ref $x) { if ($type eq 'ARRAY') { @array = @$x; } elsif ($type eq 'HASH') { %hash = %$x; } else { $obj = $x; } } else { $scalar = $x; } }