#!/usr/bin/perl use strict;use warnings; my $string = $ARGV[0]; my $test = $string; my @illegal = qw(\ * ?); my @legal = qw(bs a q); my $c = 0; foreach my $val (@illegal) { $test =~ s/\Q$val\E/[$legal[$c]]/g; $c++; } print $test."\n"; #### $ perl ./qt.pl 'a\\b\\c\d\\\\e' a[bs][bs]b[bs][bs]c[bs]d[bs][bs][bs][bs]e $ perl ./qt.pl 'foo*bar\eleven?three' foo[a]bar[bs]eleven[q]three $