Perl function to calculate a payment