You are not clear what you want, nor what your problems are, but to me it looks like you're checking whether the file starts with a 0, and then from character 10 onwards, whether it contains numbers and tabs, with no more than 20 numbers in a row, and no more than 2 tabs in a row either. Can't you just do something like:
if ($line =~ /^0/) {
my $end = substr ($line, 10);
unless ($end =~ /[^0-9\t]/ ||
$end =~ /\t\t/ ||
$end =~ /[0-9]{21}/) {
....
}
}