print "main start\n"; &mySub(4); print "main end\n"; sub mySub { my ($oldValue, $callDepth, @leftOvers) = @_; if (!defined $oldValue) { $oldValue = 0; } if (!defined $callDepth) { $callDepth = 0; } # Increment call depth each time we get into mySub() $callDepth++; my $indentSize = $callDepth * 2; my $indentSpaces = sprintf("%${indentSize}s", ""); # Show we've arrived -- indent according to call depth print "${indentSpaces}mySub($oldValue) BEGIN\n"; # Cut value in half and recurse until zero my $newValue = int($oldValue / 2); if ($newValue > 0) { &mySub($newValue, $callDepth); } # Show we've returned -- indent according to call depth print "${indentSpaces}mySub($oldValue) END\n"; # Bye-bye return; }