in reply to Help formatting text to delimited text in file

This was easy enough, I went ahead and wrote the code for you. In situations like this, use a combination of regex and split. It takes some experience to decide which to use. In general use regex when you know what to keep and use split when you know what to throw away. Below I started with a regex to make sure that I'm looking at something that looks like a valid line. Then successive splits are applied which throw away various stuff. You will have to consider if there are hyphenated names, maybe search your input for lines that contain more than the usual number of hyphens? There is always a bit of trial and error when parsing something without at formal spec that covers all cases. Good luck.
#!/usr/bin/perl use strict; use warnings; while (my $line = <DATA>) { if (my( $num, $root_name, $rest)=$line =~ /^\^(\d+)\s*%\s*(\w+)[. | +]+(.+)\+$/) { my @sub_names = split /;\s*/,$rest; foreach my $sub_name (@sub_names) { my ($name1, $name2) = split /\s*-\s*/,$sub_name; print "\"$num\",\"$root_name\",\"$name1\",\"$name2\"\n"; } } } =Prints "46004","Tamerlane","Tamerlane","Sheridan" "46004","Tamerlane","Bajazet","Barry" "46004","Tamerlane","Moneses","A Gentleman" "46004","Tamerlane","Arpasia","Mrs. Furnival" "46004","Tamerlane","Selima","Mrs. Elmy" "46005","Hamlet","Hamlet","Sheridan" "46005","Hamlet","Polonius","J. Morris" "46005","Hamlet","Laertes","Lacy" "46005","Hamlet","Ophelia","Mrs. Storer" "46005","Hamlet","Queen","Mrs. Furnival" =cut __DATA__ ^46004 % Tamerlane.| Tamerlane - Sheridan; Bajazet - Barry; Moneses - +A Gentleman; Arpasia - Mrs. Furnival; Selima - Mrs. Elmy; + ^46005 % Hamlet.| Hamlet - Sheridan; Polonius - J. Morris; Laertes- La +cy; Ophelia- Mrs. Storer; Queen - Mrs. Furnival; +