#!/usr/bin/env perl use strict; use warnings; use autodie; my %dir_tree; my $root_dir = '.'; build_dir_tree(\%dir_tree, $root_dir); sub build_dir_tree { my ($tree, $path) = @_; opendir(my $dh, $path); for (readdir $dh) { next if /^(?:\.|\.\.)$/; if (-d "$path/$_") { $tree->{$_} = {}; build_dir_tree($tree->{$_}, "$path/$_"); } else { $tree->{$_} = -s "$path/$_"; } } } { use Data::Dumper; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; print Dumper \%dir_tree; } #### ... 'pm_multi_line_match.pl' => 1025, 'pm_multi_mod_distro_test' => { 'My-Example' => { 'Build.PL' => 651, 'Changes' => 92, 'MANIFEST' => 136, 'Makefile.PL' => 730, 'README' => 1316, 'ignore.txt' => 120, 'lib' => { 'My' => { 'Example.pm' => 5155 } }, 't' => { '00.load.t' => 117, 'perlcritic.t' => 454, 'pod-coverage.t' => 437, 'pod.t' => 405 } } }, 'pm_multiline_parse.pl' => 835, 'pm_multiline_parse_hdb_prob.pl' => 601, ...