#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 } }