%hash =( a => ($b =~ /(\d+)/ ? $1 : 0), b => "test b", ); print "$_=#$hash{$_}#\n" for keys %hash;