int encode_loaded = 0; SV *m_encode = newSVpvs ("decode"); /* Or "Encode::decode", I'm not sure */ SV *sv_enc = newSVpvs ("cp1252"); my_foo (char *buffer) { int result; if (!encode_loaded) { ENTER; load_module (PERL_LOADMOD_NOIMPORT, newSVpvs ("Encode"), NULL, NULL, NULL); LEAVE; encode_loaded = 1; } PUSHMARK (sp); EXTEND (sp, 2); PUSHs (sv_enc); PUSHs (newSVpv (buffer)); PUTBACK; result = call_sv (m_encode, G_SCALAR | G_METHOD); SPAGAIN; if (result) { SV *encoded = POPs; /* Do more */ } PUTBACK; }