Perl solution

100% on Codeeval ...thanks!