#!/usr/bin/env perl use 5.010; use warnings; use strict; my %hash = (); # create empty hash my $ref = \%hash; # create reference pointing to empty hash if($ref){ say 'Reference is true'; # <- always true } else { say 'Reference is false'; } if (%$ref){ # derefence hash and check the number of elements in it say 'Hash has elements'; } else { say 'Hash is empty'; # <-- hash has no elements } $hash{a} = 1; # add a key and value to hash if (%$ref){ # derefence hash and check the number of elements in it say 'Hash has elements'; # <-- now it has one key and one value } else { say 'Hash is empty'; }