my @parts = qr/this-stuff/; if ($foo_needed) { push @parts, qr/more-stuff/i; }; my $r = join "|", @parts; $r = qr/$r/; # just to be explicit about what the string is supposed to contain