#!/usr/bin/perl -w use strict; use warnings; sub add { my ($first, @rest) = @_; if (!defined $first) { 0; } else { die "operand may not be negative!" unless $first >= 0; if ($first == 0) { add(@rest); } else { 1 + add($first-1, @rest); } } } sub print_add { print join(" + ", @_), " = ", add(@_), "\n"; } print_add 2,2; print_add 2,2,2; print_add 4,8,12;