my $len = length; $bins{$len} //= [ ]; # Set to blank array ref if not already set. push @{$bins{$len}}, $a; # Add $a to the array