my $subst = 'lc $1'; # and later $str =~ s{$pattern}{push @pos, pos $str; eval $subst; }eg