my %fruit; # create hash open(FRUIT, "fruit.csv"); while(){ @line = split (",", $_); $fruit_name = $line[0]; # the value of this is obviously apples $number = $line[1]; # the value of this is 5 $fruit{$fruit_name} = $number; # puts key-value pair (apples 5) into the hash } close(FRUIT); open(FRUITNAMES, "fruit_names.csv"); while(){ @line = split (",", $_); $thefruitsname = $line[0]; # the value of this is apples $thenumber = $fruit{$thefruitsname}; print "the number of $thefruitsname is $thenumber\n"; # this prints "the number of apples is " (WHY does this not work? NB if I change $thefruitsname to "apples" (without quotation marks) then it does print "the number of apples is 5".) }