use strict;
use warnings;
use JSON qw();
my $test = {regex => qr/^[\w\@\.]+$/, str => "this is a string"};
my $json = JSON->new();
$json->allow_blessed(1);
print $json->encode($test);
####
{"str":"this is a string","regex":null}
####
use strict;
use warnings;
use YAML qw();
my $test = {regex => qr/\w+\W+(\w+)/, str => "this is a string"};
my $yamlStr = YAML::Dump($test);
print "YAML: $yamlStr\n";
my $andBack = YAML::Load ($yamlStr);
my ($secondWord) = $andBack->{str} =~ $andBack->{regex};
print "Second word is: $secondWord\n";
####
YAML: ---
regex: !!perl/regexp (?-xism:\w+\W+(\w+))
str: this is a string
Second word is: is