What is the difference between ^ and \A , $ and \Z in regex?
See perldoc perlre.
The \A and \Z are just like "^" and "$", except that they won't match multiple times when the /m modifier is used, while "^" and "$" will match at every internal line boundary. To match the actual end of the string and not ignore an optional trailing newline, use \z .
In single-line mode, $
matches either the end of the string, or just before the newline at the end of the string. In multiline mode $
matches before each newline in the string. \Z
always matches only the end of the string regardless of the line mode. Same with ^
versus \A
.