use strict; use warnings; use Devel::Peek; my $x = ""; Dump $x; ddd($x); print $x; Dump $x; use Inline Config => BUILD_NOISY => 1, ClEAN_AFTER_BUILD =>0; use Inline 'C' => 'Config' => ccflagsex => "-g"; use Inline 'C' => <<'CODE'; int ddd(SV* x){ char* dx = "dddddd\n"; printf("string dx is %p \n", dx); // You have to use sv_use* family, since these functions free the previous PV in SV first for you, but don't use sv_usepvn otherwise perl will realloc pv. sv_usepvn_flags(x, dx, 8, SV_HAS_TRAILING_NUL); // Thanks ikegami, must set LEN to 0, otherwise, perl will try to free SV when leave scope. SvLEN_set(x, 0); return 0; } CODE #### __END__ SV = PV(0x55ac3017e050) at 0x55ac301a20b8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x55ac30220b00 ""\0 CUR = 0 LEN = 10 COW_REFCNT = 1 string dx is 0x7f0adfd33bfd dddddd SV = PV(0x55ac3017e050) at 0x55ac301a20b8 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x7f0adfd33bfd "dddddd\n\0" CUR = 8 LEN = 0