#!/usr/bin/perl -lw use strict; # [id://735593] my $string = ''; my $regex = qr||; # works # ^^^^^^^ < modified here if ( $string =~ /$regex/ ) { print "\$regex matches: $1 and $2"; } else { print "No match in $regex"; } my $OPregex= qr||; # OP's with (added) terminating "|;" if ( $string =~ /$OPregex/ ) { print "\$OPRegex matches: $1 and $2"; } else { print "no match in \$OPRegex"; }