in reply to pack() returns an unusable string
From your warning message, I would guess that your packed string '$p' has either a single quote "'" in it or an escape or $ or @ at the end that eats the closing single quote. Try looking at a dumped wersion of $p.
In Section
Seekers of Perl Wisdom