in reply to Killer byte tripping up Perl?

Just a wild guess.

while (<CMD>)
reads data line by line assuming that it is a text file with lines separated by new line characters.

If your mycmd command is producing binary output, then you probably need to read the output as binary input. Maybe you should read blocks of bytes using the read command rather than the readline function or the equivalent <...> operator.

Also take a look at the binmode function (for input as well as for output).

Update: fixed the links above to that they lead directly to the relevant Perl documentation pages instead of a search page.