c:\@Work\Perl>perl -wMstrict -MData::Dump -le "my %options = ( qr{ x (Y) z }xms => { type => 'pattern', name => 'foo', }, '(?x) x (Y) z ' => { type => 'pattern', name => 'fum', }, 'xYzzy' => { type => 'exact', name => 'bar', }, 'zzzzz' => { type => '?????', name => 'zot', }, ); dd \%options; ;; $_ = 'xYzzy'; for my $p (sort keys %options) { my ($p_type, $p_name) = @{ $options{$p} }{ qw(type name) }; if ($p_type eq 'pattern') { if ($_ =~ $p) { print qq{'$p_name' pattern match of $p, \$1 is '$1'}; } } elsif ($p_type eq 'exact') { if ($_ eq $p) { print qq{'$p_name' exact match of '$p'}; } } else { die qq{unknown: $p; type '$p_type'; name '$p_name'}; } } " { "(?^msx: x (Y) z )" => { name => "foo", type => "pattern" }, "(?x) x (Y) z " => { name => "fum", type => "pattern" }, "xYzzy" => { name => "bar", type => "exact" }, "zzzzz" => { name => "zot", type => "?????" }, } 'foo' pattern match of (?^msx: x (Y) z ), $1 is 'Y' 'fum' pattern match of (?x) x (Y) z , $1 is 'Y' 'bar' exact match of 'xYzzy' unknown: zzzzz; type '?????'; name 'zot' at -e line 1.