my @tmp; my $cur_qty; if (!defined $Output{"host"}) { $cur_qty = 0; } else { @tmp = @{$Output{"host"}}; $cur_qty = @tmp; } if (!$cur_qty) { # No saved data, just assign it $tmp[0] = $data; } elsif ($cur_qty >= 10) { # Remove oldest shift @tmp; # Add newest push @tmp, $data; } else # Just append it { push @tmp, $data; } # Save it $Output{"host"} = \@tmp;