my $char = '-'; while () { 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