You have to count all the lines of the file, you can use $. for that, heres an example withoout reading all file in an array:
#!/usr/bin/perl -w
use strict;
open(FILE,"file.txt") or die "Cant open file.txt: $!";
1 while <FILE>;
my $line=$.-30;
$.=0;
open(FILE,"file.txt") or die "Cant open file.txt: $!";
open(FILE2,">file2.txt") or die "Cant create file2.txt: $!";
while(<FILE>)
{
print FILE2 $_;
insert(*FILE2) if $.==$line;
}
rename("file2.txt","file.txt") or die "Cant rename file: $!";
sub insert
{
my $fh=shift;
print "Inserting at line $line\n";
print $fh "$_\n" for 0 .. 15;
}
$anarion=\$anarion;
s==q^QBY_^=,$_^=$[x7,print