I'm afraid you'll need a separate block of validation code for each type, but it can be done very cleanly. Try a variation of the code below:
#!/usr/bin/perl -w
use strict;
my %validators = (
'singleletter' => 'm/^[a-zA-Z]$/',
'integer' => 'm/^\d+$/',
'nottoolongstring' => 'length $_ < 10'
);
sub check
{
my ( $type, $value ) = @_;
my $v = $validators{$type};
return 0 unless defined $v;
$_ = $value;
return eval $v ? 1 : 0;
}
print check( 'singleletter', 'a' ) . "\n";
print check( 'integer', 'a' ) . "\n";
print check( 'nottoolongstring', 'a' ) . "\n";
-mk