http://www.perlmonks.org?node_id=1019974

docdurdee has asked for the wisdom of the Perl Monks concerning the following question:

Dearest Monks, I have a humble question: How do you match a variable containing a metacharacter that should be treated as a regular boring character? I'm processing some files (@foos) with dots in them. I want:
my @subfoos = grep{m/$var/} @foos;
I ended up with something awful:
my $regvar = $var; $regsol =~ s/\./___/g; my @subfoos = map {s/___/\./g; $_} grep{m/$regsol/} map{s/\./___/g; $_}@foos; }
is there a better way?