#!/usr/bin/perl -w use strict; my $string = "foobarbaz"; my $exp = "foo"; if($string =~ $exp){ print "without /'s works fine"; }elsif($string =~ /$exp/){ print "with /'s is needed"; }else{ print "WTF!??"; }