#! /usr/bin/perl use v5.14; use warnings; $_ = "He's out bowling with Fred tonight."; s/Fred/Barney/; s/with (\w+)/against $1's team/; #This is the line of code that screws up ouptut s/$1/\U$1/gi; print "$_\n";