use CGI::Safe qw/ taint /; my $q = CGI::Safe->new; #### use CGI::Safe qw/ :standard taint /; my $var = param( 'var' ) || ''; ( $var ) = ( $var =~ /^([\s\w\d]+)$/ ); #### use CGI::Safe; my $q = CGI::Safe->new; # set default tainted return to empty string $q->default_tainted( '' ); # assign the regex $q->untaint( foo => qr/^([\w\s\d]+)$/ ); # will return an empty string if it doesn't untaint my $foo = $q->param( 'foo' ); if ( ! $foo ) { error_routine( $q->tainted_param( 'foo' ) ); } #### my $foo = param( { foo => qr/^([\w\s\d]+)$/ } );