$string = 'polar BEAR'; $N = 4; $string =~ s/^.{$N}/uc $&/e; ## uppercase $N chars at start $string =~ s/.{3}$/lc $&/e; ## lowercase 3 chars at end