Starting with the original PERL code, I plan to rewrite it in PHP