%rooms = ( entrance => { description => "You enter a dimly lit room with a heavy wooden door to the north and a narrow hallway to the east.", exits => { north => "hallway", east => "storage" }, items => [], }, hallway => { description => "The hallway stretches to the north and south. A faint light flickers at the end of the south corridor.", exits => { north => "bedroom", south => "livingRoom" }, items => [], }, bedroom => { description => "The bedroom is cozy and inviting. A large bed dominates the room, and a dresser stands against the wall.", exits => { south => "hallway" }, items => [], }, livingRoom => { description => "The living room is spacious and warmly lit. A comfortable couch sits in front of a fireplace, and a large bookshelf lines the wall.", exits => { north => "hallway" }, items => [], }, kitchen => { description => "The kitchen is well-equipped with modern appliances and a large dining table. A faint glow emanates from a flashlight on the countertop.", exits => { south => "livingRoom" }, items => ["flashlight"], }, backyard => { description => "The backyard is a tranquil oasis with lush greenery and a towering oak tree. A gentle breeze rustles the leaves, creating a peaceful atmosphere.", exits => { north => "kitchen" }, items => [], }, ); $currentRoom = $rooms{entrance}; @inventory = (); do { print $currentRoom->{description} . "\n"; $input = ; chomp($input); if ($input eq "leave") { exit; } elsif ($input eq "inventory") { print "Inventory: " . join(", ", @inventory) . "\n"; } elsif ($input =~ /^take\s+(\w+)/) { $itemName = $1; if (grep { $_ eq $itemName } @{$currentRoom->{items}}) { push @inventory, $itemName; splice @{$currentRoom->{items}}, grep { $_ eq $itemName } 1; print "You picked up the $itemName.\n"; } else { print "There is no $itemName in this room.\n"; } } elsif ($input eq "help") { print "Available commands: north, south, east, west, inventory, take item, leave\n"; } else { if (exists $currentRoom->{exits}->{$input}) { $currentRoom = $rooms{$currentRoom->{exits}->{$input}}; } else { print "Invalid direction. Please enter a valid direction or type 'help' for assistance or 'leave' to end the exploration.\n"; } } } while (1);