#! perl -slw use strict; sub count_id (\@\@); # "count indivisible dividends" fnc prototype sub count_id (\@\@) { my ($divisors,$range) = (shift,shift); return 0 unless @$range && @$divisors; # check terminal condition # apply the $divisors to the dividend for this recursive call my ($aggregate,$dividend) = (0,pop @$range); for (@$divisors) { return count_id(@$divisors,@$range) if !($dividend % $_); } return 1 + count_id(@$divisors,@$range); } my @divisors = (13,17,19); my @range = (1..2310); print "Number of indivisible items: ",count_id(@divisors,@range),"\n"; __END__