I'm not too familiar with perl, but it seems like it should be able to handle these operations. A quick search shows me that exponents (that I write with a caret) use double asterisks **, so the length of leg 1 would be

pathlength1 = ( distance**2 + elevation**2 )**(1/2)

or in numbers
( 10.3625268966932**2 + 3.14960630400012**2 )**(1/2) = 10.8306

and then add all the lengths together to get

10.8306 + 29.8016 + 19.5599 + 4.67766 = 64.8697

Sorry if my abbreviations for square and square-root aren't familiar; I spend my days staring at equations and tend to forget that most people don't. Let me know if that doesn't help any!