http://www.perlmonks.org?node_id=51836
Description: Some recursion example I wrote some time again, it happens to return the directory size. There is probably more than one way to do it, this is just my way :)
#!/usr/bin/perl

sub dodir {
opendir(DIR,$_[0]);
my $dir = $_[0];
if ($dir !~ /\/$/) { $dir .= "/"; }
my @List=readdir(DIR); 
closedir(DIR);
splice(@List,0,2);
foreach $file (@List) {
my $file = $dir.$file;
if (-d $file) { dodir($file); }
else { $totsize += (-s $file); }
 }
}
dodir($ARGV[0]);
print "Reading $ARGV[0]\n";
print $totsize," bytes\n",($totsize/1024)," Kilobytes\n",($totsize/(10
+24*1024))," Megabytes\n";