The only way I know is to add an extra line and remove it later. In this way the trailing newlines are preserved since they become embedded, then you can strip the added chars using parameter substitution. This will demonstrate:
var=$(cat testfile; echo c)
echo -n "lines in variable are: "
echo "$var" | wc -l
Here is the output:
$ cat testfile
$ wc -l testfile
lines in variable are: 6
The double ?? matches the added "\n" and "c".