# setup the parser to capture the contents of all
(.*)}s # NB: "?" makes ".*" non-greedy or /(.*\?)\s+(\S.*)/s # NB: "\?" matches a literal qmark or /^([^.]+)\.\s+([^.]+\.)\s*$/s ) { push @questions, $1; push @answers, $2; } else { # you have a harder case to solve (might need a human) } }