$a = ("ac" =~ /a(b)c/) ? $1 : 'd'; print $a; #### $a = ("abc" =~ /a(b)c/)[0] || 'd'; print $a;