m/ \nid: # match new line followed by id: [^\n]* # 0 or more characters that are not new lines \n # a newline ([^\n]*\n){4}) # the next 4 lines and store in $1 /sx; # treat as a '(s)ingle line' and (x) ignore whitespace