The defined-or operator is just //. $lvalue //= "value"; actually means $lvalue = "value" unless defined $lvalue;. This means that you actually write "Key '$inData' doesn't exist.\n" in the hash :
use Data::Dumper;
my %words = ( 'hello' => 'world' );
print 'type a word: ';
chomp( my $inData = <> );
print $words{$inData} //= "Key '$inData' doesn't exist.\n";
print Dumper \%words;
type a word: Bonjour
Key 'Bonjour' doesn't exist.
$VAR1 = {
'hello' => 'world',
'Bonjour' => 'Key \'Bonjour\' doesn\'t exist.
'
};
You meant
print $words{$inData} // "Key '$inData' doesn't exist.\n"; which works fine as long as undef isn't a valid value.