@titles = qw/Dr. Col. Miss/; # list of allowable titles $title_reg = join "|", @titles; $title_reg =~ s/\./\\./g; # make sure the dots are literal while (<>) { / ($title_reg)? # optional title \s* # skip any spaces (\S+) \s+ # first name, skip following spaces ((?:\w\.\s*)+)? # middle initials - any number, optional (\S+) # last name /iox; print "$1, $2, $3, $4\n"; }