You're better off using a regex for this. In particular, a m//g (global) match in scalar context:
my $char = '-'; while (<DATA>) { print; while (/($char+)/g) { my $to = pos(); my $from = $to - length($1) + 1; print " Found $char at $from to $to\n"; } } __DATA__ A-----B A----C---B
Output:
A-----B Found - at 2 to 6 A----C---B Found - at 2 to 5 Found - at 7 to 9
In reply to Re: Regular Expression Search
by Eliya
in thread Regular Expression Search
by Monk007
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |