use File::Slurp; my %h; @h{map{chomp;$_}read_file("test1.txt")}=(map{chomp;$_}read_file("test2.txt"));