# use strict, etc... OUTER: while ( 1 ) { INNER_A: while ( my $dir_A = readdir( $dh ) ) { # something4 INNER_B: while ( my $dir_B = readdir( $dh ) ) { INNER_C: while ( my $dir_C = readdir( $dh ) ) { # something6 next INNER_C if ...there are still files in the folder that have not been checked...else return to OUTER; } next INNER_B if ...there are still files in the folder that have not been checked...else return to OUTER; } next INNER_A if ...there are still files in the folder that have not been checked...; } sleep 2; next OUTER if the network is not too busy; # I have no idea how or if I should do this sleep 4; }