use strict; use warnings; use feature qw{ say }; my %allowed = map { $_ => 1 } qw{ name user host command }; my @commands = ( { name => q{Fred Bloggs}, user => q{fbloggs}, host => q{red}, command => q{ls},, }, { name => q{Charlie Farley}, user => q{cfarley}, host => q{green}, zone => q{A}, building => q{Chaucer}, command => q{ps}, }, ); for my $command ( @commands ) { my @badKeys = grep { not exists $allowed{ $_ } } keys %$command; say @badKeys ? qq{Command invalid: bad keys: @badKeys} : q{Command OK}; } #### Command OK Command invalid: bad keys: zone building