in reply to multi-line match
If there is any chance of there being more than one blank line between your records, you should set $/=''; to enable "paragraph mode" in preference to "\n\n".
To quote from perlvar:$INPUT_RECORD_SEPERATOR:
Setting it to "\n\n" means something slightly different than setting to "", if the file contains consecutive empty lines. Setting to "" will treat two or more consecutive empty lines as a single empty line. Setting to "\n\n" will blindly assume that the next input character belongs to the next paragraph, even if it's a newline.
If your files are not too big, you could also set local $/=undef; (or simply, local $/;) to read the whole file into a scalar and then use m//g in a while loop to process the records.
$s = "abc\ncd\ne\n\npqr\nst\nf\n\n"; while( $s =~ m[ (\w+) \n (\w+) \n (\w+) ]gx ) { print "$1:$2:$3"; } abc:cd:e pqr:st:f
|
|---|