use Devel::Peek; my $x = ""; Dump $x; ddd($x); Dump $x; use Inline 'C' => <<'CODE'; int ddd(SV* x){ char* dx = "dddddd\n"; char* bbb=NULL; Newx(bbb, 8, char); Copy(dx, bbb, 8, char); printf("string dx is %p \n", dx); printf("string bbb is %p \n", bbb); // sv_setpvn(x, dx, 8); #copy string to a SV // sv_usepvn(x, dx, 8); #segment fault! sv_usepvn(x, bbb, 8); #"attach" to a SV return 0; } CODE ########## output ########## SV = PV(0x559f4143cfd0) at 0x559f41461018 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x559f414d58a0 ""\0 CUR = 0 LEN = 10 COW_REFCNT = 1 string dx is 0x7f12ed54f8d8 string bbb is 0x559f41462ad0 SV = PV(0x559f4143cfd0) at 0x559f41461018 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x559f41462ad0 "dddddd\n\0"\0 CUR = 8 LEN = 16