#!/usr/bin/env perl use strict; use warnings; use Test::More; my @tests = ( ['a!b@c#', 'a\!b\@c\#'], ['{d}e(f)', '\{d\}e\(f\)'], [q{g"h'i}, q{g\"h\'i}], ['[/].\\', '\[/\].\\\\'], ); plan tests => 0+@tests; my $re = qr{([^0-9A-Za-z./])}; for my $test (@tests) { my ($got, $exp) = @$test; $got =~ s/$re/\Q$1/g; ok $got eq $exp; } #### 1..4 ok 1 ok 2 ok 3 ok 4