my $pat = "/etc/"; my $string = "/usr/etc/config"; if ($string =~ m/$pat/x) { print "it matches\n"; }