#!usr/local/bin/perl $filename = "input.txt"; open (FILE,"<$filename"); @fileinput=; close(FILE); foreach $line(@fileinput) { my $test=($line); #add written by and capital the first letter of each word if($test=~s/AU: \b(\w+)|AU: \b(w+)\s\b(w+)/AU: Written by: \u$1 \u$2/g) { print $test; } }