for my $key (keys %$sth) { say $key, ' : ', ($sth->{$key} // 'undef'); # Use this if your Perl version < 5.10 #print $key, ' : ', (defined $sth->{$key} ? $sth->{$key} : 'undef'), "\n"; }