What are you tring to do in that regex? It looks like you are trying to find any case where a newline is followed by at least one character, and then that leads you to print the line number ($.
) of whatever matches that criterion.
If you don't mind my asking, what's the larger purpose here?
In any case, see this article for a clear discussion of multiline matching: Regexp Power
Edited after the move to SO: If what you really want is to find the lines with less than 75 characters and a next line beginning with a space, I wouldn't use one regex. The description points to an easier and clearer (I think) solution: (1) filter out all lines with less than 75 characters (the length
function is good for that). For the lines that remain, (2) check if the next line starts with a space. That gives you clear logic and an easy regex to write.
In response to the question about getting the "next" line. Think of it the other way around: you want to check every next line, but only if the previous line was less than 75 characters. So how about this:
my $prev = <>; # Initialize $prev with the first line
while (<>) {
# Add 1 to 75 for newline or chomp it perhaps?
if (length $prev < 76) {
print "$.: $_" if $_ =~ m/^\s/;
}
$prev = $_;
}
(Note that I don't know anything about vCard format and that \s
is broader than literally "a single space." So you may need to adjust that code to fit your problem better.)