There is no @fruits
array, so $fruit = $fruits[<STDIN>]
makes no sense. $fruit
will be set to undef
which evaluates as zero in a numeric context
Meanwhile, $fruit_list{'1'}
is Apple
, which also evaluates as zero in numeric context
The ==
operator compares numbers, so if ($fruit == $fruit_list{'1'})
will compare zero with zero and always find a match
You must have seen warning messages when you run your program. You must never ignore such messages as they are there to help you
You must add use strict
and use warnings 'all'
to the the top of every Perl program you write, and fix all resulting messages before asking others for help
You must also lay your code out properly, including indentation, so that other people (and yourself) can read it easily. I have edited the code in your question: please do it yourself in future, at least before asking other people for help with your code