You are correct, Data::Dumper prints the '\0' but it is only visible in the output via something like cat -v. Nice trick btw, I didn't know about that. Thank you!
Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.