Just so you can see the code easily I've include [link|http://www.gregfolkert.net/sources/flip-1.19/flip.c|flip.c as a link here], [link|http://www.gregfolkert.net/sources/flip-1.19/flip.h|flip.h] (actually the whole debian source for it [link|http://www.gregfolkert.net/sources/|here])

I thought it might give you an idea or something. As I guess the someone you are researching for only wants to do this in Perl.