my $iLength = length('AU: Written by:'); # read lines one at a line instead of slurping into an array # this is more memory friendly while (my $line = ) { # single out lines beginning with 'AU' for special processing if ($line =~ /^AU:/) { # insert "Written by" # Note: substr on the left means # replace the zero-length string at position 3 # in other words: insert something at position 3 substr($line, 3,0) = ' Written by:'; # capitalize the first letter of every word # Note: substr on the left means # make substitutions in the part of the string after # "AU: written by" substr($line, $iLength) =~ s/\s(\w+)/ \u$1/g; } print $line; }