# Slurp the file my $Text=do { local $/; }; # Assuming that a question begins with a number followed by a period: # Then a question is a question number followed by lines which are not question numbers. #while ($Text =~ m{(\d+\.\n([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+)}s) { while ($Text =~ m{((\d+)\.\n(([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+)(A\)([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+?)(B\)([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+?)(C\)([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+?)(D\)([^\n\r\f]*[a-zA-Z]+[^\n\r\f]*\n)+))}gs) { ### question number :$2 ### question :$3 ### A) :$5 ### B) :$7 ### C) :$9 ### D) :$11 #using g so #$Text=$'; };