in reply to Directory size 1 level deep

You need a way to transform the directory the file is in to the appropriate top-level directory. Use the File::Basename module, then something like:
sub topdir { my($nd,$parent)=@_; my $d = $nd; # Hack; strip off trailing characters that might be directory # seperators $parent =~ s/\W$//; while ($nd ne $parent) { $d = $nd; $nd = File::Basename::dirname($d); } return $d; }
That HACK line is in case the argument is c:\temp\ instead of just c:\temp. It should really be $dir=join("",fileparse($dir));, but that doesn't work as documented on my system.

The code to use this is:

#!/usr/bin/perl -w use strict; use File::Find; use File::Basename; our $dir = $ARGV[0]; find(\&do_dir, $dir); my %hash; sub do_dir { my $size = -s ($File::Find::name) or return; my $d = topdir($File::Find::dir,$dir); if (!defined($hash{$d})) { $hash{$d} = 0; } # warn "size=$size, d=$d\n"; $hash{$d} += $size; } foreach (keys %hash) { print "DIR $_ = $hash{$_}\n"; }