#### #text is put in an array called page_text foreach my $new_line(@page_text) { #put each line into another array my @blankPages = ($new_line =~ m/]+?title\s*=\s*["']?([^'" >]+?)[ '"]?>/sig); foreach my $blankTitle(@blankPages) { print "$blankTitle is the title\n"; #do some logic to add a blank page with that title } } #### if ($new_line =! m/sameregexasabove?/sig) { #don't write a new line with the xml tag, but any other text is okay }