#!/usr/bin/perl use strict; use Data::Dumper; my %hash; my $value = "determined at run time"; while () { chomp; eval '$hash{' . join( "}{", split(/\//) ) . "} = '$value'"; } print Dumper(\%hash); __DATA__ root/dir1/file1 root/dir1/file2 root/dir1/file3 root/dir2/file1