str.gsub(/\bam\b/) { |match| match.upcase } #=> "I AM a string"