sub recurse { my ($param1, $param2, ...., $aPath) = @_; $id = getIdOfCurentNode(); .... do some stuff ... if ($bNeedToRecurse) { push @$aPath, $id; recurse($param1, $param2, .... $aPath); pop @$aPath; } elsif ($bSomeProblemFound) { print "Error Blah found at node=<@$aPath>\n"; } }