#!/usr/bin/perl -w use strict; use File::Find; use File::Spec::Functions qw(splitdir); use Data::Dumper; my %hash; find( sub { return if $_ eq '.' or $_ eq '..'; my $cursor = \%hash; $cursor = $cursor->{$_} ||= {} for splitdir $File::Find::dir; -d $_ ? $cursor->{$_} = { "." => [] } : push @{$cursor->{"."}}, $_; }, @ARGV); print Dumper \%hash;