while ($string =~ /($regex)/pg){ my $match = ${^MATCH}; my $start = $-[0]; my $end = $+[0]; my $hitpos = "$start-$end"; my $lcmatch = lc($match); $string =~ s/$match/$lcmatch/g; push @matches, "$match found at $hitpos "; }