answer 6 in Perl