use strict; use warnings; use Cwd; use JSON; my %hash; my $currDir = Cwd::cwd(); push @{ $hash{$currDir} }, { name => $_, size => ( stat($_) )[7] } for <*>; my $j = encode_json \%hash; print $j; #### {"/home/user/programming/Perl/tmp":[{"name":"File1.txt","size":63},{"name":"File2.txt","size":55},{"name":"temp5.pl","size":196},{"name":"test.pl","size":197}]}