merlyn has mentioned a neat module called Inline to make this really easy. Rather than write XS, take Perl functions and write equivalents in C, then inline. The rest is taken care of for you. (Supposed to be.)
I have not pushed it, but give it a shot.