$b = 'test 100'; %hash = ( a => ($b =~ /(\d+)/ ? $1 : 0), b => ($b =~ /(\w+)/ ? 1 : 0), ); print "$hash{a}\n";