=usage reduce \&f @x; eg. reduce {$a+$b} @x; # sum @x reduce {$a*$b) 1..7 # factorial(7) = 7! =cut sub reduce (&@) { my $f = shift; local ($a, $b) = shift; $a=&$f while $b=shift; return $a; } my $x = reduce { $a*$b } 1..7; print $x;