use File::Find; use File::stat; our @current_bucket; our $current_size = 0; our $BUCKET_SIZE = 4000000000; sub add_to_bucket { my $size = stat($_)->size(); if ($size + $current_size > $BUCKET_SIZE) { # reset bucket process_bucket(\@current_bucket); @current_bucket = (); $current_size = 0; } $current_size += $size; push @current_bucket, $File::Find::name; } sub process_bucket { my $bucket = shift; # here do things like compress the list to contain # parent directories, etc, if you really need to do this # then print out the list. } find(\&add_to_bucket, "/data");