I like your solution. The regex could be different if OP really only wants to delete keys with single digits instead of multiple digits. I suggest using the arrow notion when using a hash reference.
use strict;
use warnings;
use Data::Dumper;
my $hash = {
'abc' => {
def => 1,
ghi => 2,
jkl => 3,
},
'mno' => {
pqr => 4,
stu => 3,
vwx => 5,
},
2 => {
def => 5,
stu => 2,
},
0 => {
def => 3,
stu => 1,
},
123 => {
xyzzy => "and nothing happens"
},
};
#print Dumper $hash;
for my $key (keys %$hash) {
delete $hash->{$key} if $key =~ /^\d$/
}
print Dumper $hash;
__END__
$VAR1 = {
'123' => {
'xyzzy' => 'and nothing happens'
},
'abc' => {
'def' => 1,
'jkl' => 3,
'ghi' => 2
},
'mno' => {
'stu' => 3,
'pqr' => 4,
'vwx' => 5
}
};