sub move_disks_from_one_peg_to_another_peg_using_a_third { my ($n, $peg_a, $peg_b, $peg_c) = @_; if ($n == 1) { print "Move disk #1 from $peg_a to $peg_b.\n"; return; } else { move_disks_from_one_peg_to_another_peg_using_a_third($n-1, $peg_a, $peg_c, $peg_b); print "Move disk #$n from $peg_a to $peg_b.\n"; move_disks_from_one_peg_to_another_peg_using_a_third($n-1, $peg_c, $b, $peg_a); return; } }