if ( 1 == $x ) { ... # $y cleaned } else { ... # $y not cleaned $y = pack "A*", $y; if ( tainted( $y ) ) { $y =~ s/[;\\'"\*]//g; } } open my $file, '<', $y;