my $reg = qr/[^a-z]/i; $reg=~s!\(\?\^([^:]+):(.+)\)$!/$2/$1!; my %var = (reg => $reg); my $json = JSON->new->latin1->encode(\%var);