We usually think of /./ as meaning "match any character". /\w/ means match any word charcter (/[a-zA-Z_0-9]/).

In your example, this would not make a difference. Note that in your second case, you use .* rather than \w+. The "+" requires atleast one match. The "*" does not. That is the difference. Good Luck, Bill

The pattern ^.* at the beginning of a regexp is redundant, so you basically match

SUB:.*[^;]$

Since you are using the m-modifier for your regexp, the $ changes its meaning from matching end of the string to matching end of the line. That is, your pattern matches, if $qpar contains the text SUB:, and somewhere later a \n which is not immediately preceeded by a semicolon. For instance, the following string would match:

"xxxxSUB:yyyy\n\nSUB:\nbbbbbb"

In this case, the matched substring would be

SUB:yyyy\n\nSUB:\n

If you would have used .*? instead of .*, the matched substring would be

So, what I need is to match "....SUB....[^;]" , independent if there is a \n at the end. I don't know if it's possible in just one regexp or I should check it in two regexp (one with "\n" at the end, another without "\n").

For Laurent: yes is exactly what I need, but I don't understand few codes:

Why do you execute:

Code

chomp $qpar;

the you repeat chomp in next instruction code?

Code

$qpar .= <DATA> and chomp $qpar while ($qpar !~ /;\s*$/);

what is ".=" ?

for rovf: sorry, maybe I was just confusing to explain. I have a log file where all the relevant lines have word "SUB" at the beginning of line (but not the first characters) and ending with semicolon. In some case this line is split on more lines, so I have this string start at line and end in the next line (where semicolon is). I have to "normalize" this situation before to print them. Last problem is that ";" could have a "\n", or not (if it's at the end of file, whitout any other line next).

In this case, I would ignore the \n completely. Just find SUB, followed by any text, up the next semicolon. You just need to make sure that the dot matches the newline, otherwise your pattern will faile. I.e. you need something like

This says: if $qpar does not end with a semi-colon (;) possibly followed by some spaces, then get the next line of input, concatenate it with the current $qpar, chomp the new $qpar (this is needed since a new line was added at the end of $qpar, you need to remove the new line characters again), and do all this as long as the new line you get is not ended by a semi-colon.