in reply to A very deep recursion and the GD module (problem)

I don't know about Windows, but in UNIX your list of files in:
opendir (DIR, $directory); @files = readdir DIR; closedir DIR;
will include both ".", the current directory, and "..", the parent directory. These will cause your program to look at your entire hard drive over and over again.

The normal way to deal with that is, in your for $file loop, to add a line like next if ($file =~ /^\./);.