You can turn on the "pack" warning category and make it fatal. Then an overflow would cause an exception which can be trapped. E.g.:
for my $val (127, 128) {
print "$val -> ";
if (eval {
use warnings FATAL => qw(pack);
pack("c", $val);
}) {
print "no overflow";
} else {
print "overflow ($@)";
}
print "\n";
}
Another possibility is to use a (preferably local-ized) $SIG{__WARN__}
handler and check in the handler if a warning happened.