in reply to Extraneous Data in Variable

It is hard to guess if your code really does what you think it does - we only have your word for it. Considering that substr works for a lot of other people, so it is much more likely that the bug is in your code, rather than in substr.

For instance, you say:
Field Length ($length) is the result of the Perl length($field) function.
Trim Length ($trim_length) is the result of substr ($field, 0, $length).
But that means that if you put the two together, you get:

substr($field,0,length($field));
Which means "extract from the string everything between the start of the string and the end of the string, and return it". You get the whole string, naturally.

And where do the newlines come from, that we see in the value of Field and Trim Length?

Can you post a short example that demonstrates the problem? Maybe then we can spot your error for you.