#!/usr/bin/perl -w use strict; my $code = "xx;1:{}/x %"; # I want to keep "/" from being filtered out $code =~ s/[^\w"':.;]//g; print $code;