use strict; use warnings; my $str1=''; sub funky { my $count = shift; return if $count > 5; $str1 = 4*$count; my $indent = "funky" . " "x$count; print $indent,"before recurse: count=$count, str1=$str1\n"; funky($count+1); print $indent,"after recurse: count=$count, str1=$str1\n"; } sub monkey { my $count = shift; return if $count > 5; my $str = 4*$count; my $indent = "monkey" . " "x$count; print $indent,"before recurse: count=$count, str=$str\n"; monkey($count+1); print $indent,"after recurse: count=$count, str=$str\n"; } funky(0); monkey(0); #### $ perl recurse.pl funkybefore recurse: count=0, str1=0 funky before recurse: count=1, str1=4 funky before recurse: count=2, str1=8 funky before recurse: count=3, str1=12 funky before recurse: count=4, str1=16 funky before recurse: count=5, str1=20 funky after recurse: count=5, str1=20 funky after recurse: count=4, str1=20 funky after recurse: count=3, str1=20 funky after recurse: count=2, str1=20 funky after recurse: count=1, str1=20 funkyafter recurse: count=0, str1=20 monkeybefore recurse: count=0, str=0 monkey before recurse: count=1, str=4 monkey before recurse: count=2, str=8 monkey before recurse: count=3, str=12 monkey before recurse: count=4, str=16 monkey before recurse: count=5, str=20 monkey after recurse: count=5, str=20 monkey after recurse: count=4, str=16 monkey after recurse: count=3, str=12 monkey after recurse: count=2, str=8 monkey after recurse: count=1, str=4 monkeyafter recurse: count=0, str=0