Repeated applications of index would do it:
my $foo = "1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 12345678901234567890123456789012345678901 123456789012345678901234567890123456789012 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890"; my ($this, $prev, @short) = (0,0); while (@short < 4) { $this = index $foo, "\n", $prev; push @short, substr $foo, $prev, $this - $prev if $this - $prev <= 40; $prev = $this + 1; } { local $, = $/; print @short; }
I expanded the data to show it's doing the right thing.
After Compline,
Zaxo
In reply to Re: How do I match lines of 40 characters long in a block of text?
by Zaxo
in thread How do I match lines of 40 characters long in a block of text?
by kleinbiker7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |