in reply to Re^2: run program until directory is not empty
in thread run program until directory is not empty

use strict ; use warnings ; my $dir = "/var/tmp/monk"; chdir("$dir") or die "$!"; opendir(DIR, $dir) or die "Can't open $dir: $!"; sub task { my $entry = shift || 'n/a' ; # got an entry, do something print 'got one: ', $entry, "\n" ; } sub check { my $entry = readdir DIR ; while ($entry && ($entry eq '.' || $entry eq '..')) { $entry = readdir DIR ; } if ($entry) { task($entry) ; check() ; } else { close DIR ; # uncomment for a script you can daemonize #sleep 1 ; #opendir(DIR, $dir) or die "Can't open $dir: $!"; #check() ; } } check() ;

P.S. This takes the previous example and makes it recursive which is what the OP asked for.