Use Modern::Perl and say instead of print "…\n"
Use sum() from List::Util