add recurse method (perl version)