map { my $val = (split /\//, $_)[-1]; (my $key = $val) =~ s/\.txt//; $testhash1{$key} = $val } @teststr;