#!/usr/bin/perl -w use strict; my $chr; $chr = "this and that"; $chr =~ s/(this|that)|(\w+)/$1\U$2/g; #error reported print "$chr\n";