#!/usr/bin/perl -w $| = 1; use strict; use File::Find; use FileHandle; use Net::DNS::ZoneFile; my $base = "/chroot/named/master/arpa/in-addr/68/168"; my $out_dir = "/var/tmp/ptr"; find(\&wanted, $base); exit; sub wanted { return unless ( -f "$File::Find::name" and $File::Find::name !~ m!/com/! ); return unless ( -f "$File::Find::name" and $File::Find::name !~ m!/net/! ); # Here we get the rootdir as an argument to the wanted function # then we are going to need to open it as a new filehandle # so that the module can read it. my $root = shift; my $zone = new FileHandle "$File::Find::name", "r"; my $out = join('.', ( split('/', $File::Find::name) )[-1,-2,-3]); my $rrset = Net::DNS::ZoneFile->readfh($zone, $root); # here you were printing to STDOUT, as opposed to OUT # which is what I assumed you wanted to do. open(OUT, ">$out_dir/$out") or die "Cant create $out_dir/$out: $!\n"; print OUT $_->string . "\n" for @$rrset; close(OUT); }