12.4. End of String
Perl provides a variant of the \z marker: \Z. Whereas lowercase \z means "match at end of string", capital \Z means "match an optional newline, then at end of string". This variant can occasionally be convenient, if you're working with line-based input, as you don't have to worry about chomping the lines first: # Print contents of lines starting with --... LINE: while (my $line = <>) { next LINE if $line !~ m/ \A -- ([^\n]+) \Z/xm; print $1; } But using \Z introduces a subtle distinction that can be hard to detect when displayed in some fonts. It's safer to be more explicit: to stick with using \z, and say precisely what you mean: especially if what you actually meant was: Using \n? \z instead of \Z forces you to decide whether the newline is part of the output or merely part of the scenery. |