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 #### A-----B Found - at 2 to 6 A----C---B Found - at 2 to 5 Found - at 7 to 9