in reply to why is substr behaving odd?
substr can take a third parameter indicating length, not ending position. In other words:
my $sub = substr ($seq, $end, 1000); [download]
I hope this helps you with your problem.