# Map keys to coderefs (used sort of like a switch statement) my %ActionMap = (post => sub{ $allowed{msgid} = '^(\d+|new)$'; $allowed{data} = '^(([^|+]*[^|]+.*\|){4}[^|+]*[^|]+.*)$'; }, edit => sub{ $allowed{msgid} = '^(\d+|new)$'; }, delete => sub{ $allowed{msgid} = '^(\d+)$'; }, long => sub{ $allowed{sort} = '^(author|date|subject|expire)$'; $allowed{msgid} = '^(\d*|all)$'; }, short => sub{ $allowed{sort} = '^(author|date|subject|expire)$'; $allowed{msgid} = '^(\d+|all)$'; }); # "Call" the coderef matching the "switch" value $ActionMap{$query->{action}}->(); for my $key (keys %$query){ return 0 unless exists $allowed{$key} && $query->{$key} =~ /$allowed{$key}/; }