in reply to php to perl

Search CPAN for Math and you will find modules like Math::Trig that have all the functions like acos and deg2rad available in perl. The rest of the conversion seems trivial (like replacing "sub" for "function")