my $N = 7; $str='polar bear'; $str =~s#^(.{$N})(.*)(.{3})$#\U$1\E$2\L$3#gsi; print $str; output: ********* POLAR Bear