use Tie::File; tie my @file, 'Tie::File', 'file.txt' or die $!; shift @file if @file == 8; ... push @file, 'new data'; ... untie @file;