JSON objects translated to Perl hash references use : as the separator instead of , or =>, which causes syntax errors.
There can be unbalanced braces in generated code, which causes syntax errors.
JSON containing embedded newlines is single quoted, which double escapes the newlines, causing literal \n characters to appear in embarrassing places. This can be avoided by using qq'...' or regular double quotes instead of single quotes, however that will trigger Perl's string interpolation on the entire string, so it might be necessary to only double quote the newlines:
my $hr = {
'abc' => 'def' ."\n". 'ghi',
};
In order to see this in action, head over to the SparkPost API docs, click the < on the black background near the top right hand corner, click Create Transmission with Inline Parts Content, and scroll down to select Perl from the language dropdown.