my %RULES = ( 'post' => { 'msgid' => '^(\d+|new)$', 'data' => '...', }, 'edit' => { 'msgid' => '^(\d+|new)$', }, ..., }; my $allowed = $RULES{ $query->{'action'} }; foreach $key (keys %$query) { exists $allowed->{'key'} ? 1 : return 0; ... } #### for ($query->{'action'}) { $allowed = /post/ ? { ... } : /edit/ ? { ... } : /delete/ ? { ... } : die "that action isn't supported"; } #### local $_ = "0A72656B636148206C72655020726568746F6E41207473754A"; while(s/..$//) { print chr(hex($&)) }