# %folders has each folder ID as a key and the name as the value # @subfolders is the Folder/Folder data as shown above, line-for-line foreach my $k (sort (keys (%folders))) { $folderpaths{$k} = &build_path($k,@subfolders); print "$k => $folderpaths{$k}\n"; } sub build_path($@) { my $folderid = shift @_; my @dumpff = @_; my $path = "$folderid"; my $parentid = ""; foreach my $line (@dumpff) { if ($line =~ /^Folder (\d{3,5})\s+\-\s+.*\./) { $parentid = $1; } elsif ($line =~ /\s+subfolder\s+$folderid\s+\-\s+.*\./) { $path = join('/', &build_path($parentid,@subfolders),$folderid); } } return $path; }