#!/usr/bin/perl # # get last x items of an array my $howmany = 5; my @in = qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20); my @arr; my $ct = 1; foreach $line (@in) { push (@arr, $line); if ($ct > $howmany) { shift (@arr); } $ct++; } foreach $item (@arr) { print "$item\n"; } __END__