$regex = qr/(test)foo/i; #then to use it $var =~ $regex;