if ( $text =~ m/cow\s+(jumped)\s+over/ ) { $1 = "tripped"; }