#! /usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; while(){ next if($_ =~ /^\s*?$/); $_ =~ s/^\s+//; my $path = $_; $path =~ s/^\///; #/ my ($key,$sub) = split(/\//,$path,2); $hash{$key} = insert_rec($key,$sub,$hash{$key}); } print Dumper(\%hash); # insert_rec builds the hash recursivly. # Parameters: # key of anonymous hash that has to be expanded # remaining path # reference to hash sub insert_rec{ my ($key2,$path,$hashref) = @_; my ($key,$sub) = split(/\//,$path,2); unless($sub){ $hashref->{$key} = {}; return($hashref); } $hashref->{$key} = insert_rec($key,$sub,$hashref->{$key}) if($sub); return ($hashref); }# end insert_rec # ohne Leerzeichen: _ _DATA_ _ verz1/datei4 test verz1/verz2/verz3/file3