in reply to substr is behaving differently with small vs large strings

It seems that your code works correctly. May be something wrong with data? Anyway I can suggest to improve you code, sub editcontig can be eliminated:
my $rawseq = <CONTIG>; # my $goodseq = editcontig($rawseq); $rawseq =~ tr/ \t\n0-9//d; # now use $rawseq instead of $goodseq