for my $key( keys %{$moon->phase > 0.25 ? $thisref : $thatref} ) { ... } # or, more likely to be encountered push @{$val % 2 ? \@odds : \@evens}, $val;