for (qw(CamelCase AStringWithFTP AStringWithFTPOrSFTP)) { my @parts = /[A-Z](?:[A-Z]+|[a-z]*)(?=$|[A-Z])/g; print "$_ => @parts\n"; } # outputs: # CamelCase => Camel Case # AStringWithFTP => A String With FTP # AStringWithFTPOrSFTP => A String With FTP Or SFTP