for(;;) { begining: print "A\n"; foreach my $job (read_dir("G:/Input")) { print "B\n"; next unless $job =~ /(.{1,36})\.txt$/; my $tag = $1; ##'when you have checked all the files' GOTO beginning foreach my $job (read_dir(G:/Output")) { print "D\n";