my @a = qw(1 2 3 4 5); for (1..5){ shift @a if @a == 8; push @a, 'new data'; } print "$_\n" for @a;