I've found it useful for myself in the past to break down the steps involved, rather than trying for that one great swoopy assignment right off the bat.
my $headers = $entity->head();
die "No headers in entity!" unless defined $headers;
my $subject = $headers->get('Subject');
$subject ||= '(empty)';
print "Subject is: $subject\n";
Once you get it working, you can try collapsing it back to something briefer, or not, depending on clarity and your specific needs. But for starters, I would try breaking down the steps and insuring each one works along the way.
Peace,
-McD