I have written a module to do this type of things (and many others, such as comparing files in a very detailed way) on arbitrary large sorted files. It has a detailed documentation and I have been using it happily at my job for the last few months, but I still am not sure on how to provide an adequate test suite for different OS's to upload it to the CPAN (basically, I do not figure out how to provide test samples adequate for different end-of-line characters across various OS's). I can provide the module to you if you wish to try it.
Anyway, the following is an extremely simplified command-line version of the algorithm used by this module for removing duplicates from a file (whatever the definition of duplicate is for your particular problem):
$ cat test.txt
AB000000026JHAHKDFK
AB000000028JHKHKHKJ
AB00000003033AFSFAS
AB000000030HJHKH80J
AB000000030LOIKJUJ8
AB0000000324446KJHK
$
$ perl -ne '$c = substr ($_, 9, 2); print if $c ne $prev_c; $prev_c=$c
+;' test.txt
AB000000026JHAHKDFK
AB000000028JHKHKHKJ
AB00000003033AFSFAS
AB0000000324446KJHK