use Carp; my %allowed_keys; my %allowed_values; sub function { my ( $arrayref, $hashref ) = @_; croak 'First Argument has to be an Arrayref' if !defined $arrayref or ref $arrayref ne 'ARRAY'; my %hash=( ... ); # vordefiniert if ( defined $hashref ) { croak 'Second Argument has to be an Hashref' if ref $hashref ne 'HASH' # test keys und values my @not_allowed_keys=grep{ !$allowed_keys{$_} }keys(%$hashref); my @not_allowed_vals=grep{ !$allowed_values{$_} }values(%$hashref); carp 'Ignoring Keys :'.join( ', ', @not_allowed_keys ) if @not_allowed_keys; carp 'Ignoring Values :'.join( ', ', @not_allowed_vals ) if @not_allowed_values; %hash=map { $_ => $hashref->{$_} } grep{ $allowed_values{ $hashref->{$_} } } grep{ $allowed_keys{$_} } keys %$hashref ; } my @return; ... ... return @return; }