use Inline C => qq{ SV* swap(SV* one, SV* two) { char *buf1, *buf2, *buf3; STRLEN idx, len; SV* ret; if (!SvPOK(one) || !SvPOK(two) || sv_len(one) > sv_len(two)) return newSVsv(&PL_sv_undef); len = sv_len(one); buf1 = SvPVX(one); buf2 = SvPVX(two); buf3 = malloc(len); for (idx=0; idx < len; idx++) { buf3[idx] = buf1[idx] ? buf1[idx] : buf2[idx]; } ret = newSVpv(buf3, len); free(buf3); return ret; } }; # [ your code, but with ] cmpthese( -5, { 'split1' => sub { my $s3 = split1( $s1, $s2 ) }, 'substr1' => sub { my $s3 = substr1( $s1, $s2 ) }, 'inline' => sub { my $s3 = swap($s1, $s2) }, });