#!/usr/bin/perl -w use strict; my @tests; push (@tests, q($foo)); push (@tests, q($foo[0])); push (@tests, q($foo{bar})); push (@tests, q($foo{'bar'})); my $foo = 'scalarfoo'; my @foo = qw(arrayfoo); my %foo = ( 'bar' => 'hashfoo' ); foreach my $foo (@tests) { $foo =~ s/(\$[\w\[\]{}"']+)/qq($1)/gee; print $foo, "\n"; }