use Validate; my ($method, $error) = Validate->checked ($query->param('method'), 1); if ( $error->{ msg } ) { push @errors, "A method $error->{ msg }" } package Validate; sub checked { my ($class, $value, $mandatory) = @_; print Dumper ($class, $value, $mandatory); if (!$value && $mandatory) { return (undef, { msg => 'must be checked' }); } else { return ($value); } } 1;