use Config qw( %Config );
use Devel::Peek qw( Dump );
my $ptr_size = $Config{ ptrsize };
my $ptr_format =
$ptr_size == 4 ? "L" :
$ptr_size == 8 ? "Q" :
die( "Unsupported pointer size $ptr_size\n" );
# https://perldoc.perl.org/perlapi#SvPV_force
sub SvPV_force { unpack $ptr_format, pack "P", $_[0] }
my $s = "abc";
Dump $s;
printf "%x\n", SvPV_force( $s );
Dump $s;
####
SV = PV(0x57565c72fee0) at 0x57565c75e0d0
REFCNT = 1
FLAGS = (POK,IsCOW,pPOK)
PV = 0x57565c761a90 "abc"\0
CUR = 3
LEN = 16
COW_REFCNT = 1
00.00.57.56.5c.78.5b.c0
SV = PV(0x57565c72fee0) at 0x57565c75e0d0
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x57565c785bc0 "abc"\0
CUR = 3
LEN = 16
####
use B qw( svref_2object );
# https://perldoc.perl.org/perlapi#SvPVX
sub SvPVX { svref_2object( \$_[0] )->PV }
my $s = "0123456789";
printf "%x\n", SvPVX( $s ) while $s =~ /\G./g;