#!/usr/bin/env perl use warnings; use strict; use Hash::Util qw/lock_hash/; my %x = ( foo => "bar" ); lock_hash %x; eval { $x{y}++; 1 } or warn $@; eval { $x{foo}="quz"; 1 } or warn $@; __END__ Attempt to access disallowed key 'y' in a restricted hash at lock.pl line 9. Modification of a read-only value attempted at lock.pl line 10.