in reply to Regular Expression Search

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

See m//g and pos.

Replies are listed 'Best First'.
Re^2: Regular Expression Search
by Monk007 (Initiate) on Feb 09, 2012 at 18:50 UTC

    Thanks !