my $alt = join '|', keys %substitute; # make one string of all # keys with pipes between my $regex = qr/($alt)/; # compile the regex # with parens to capture