sub foo { my $client = 'a.b'; my $re = eval shift; grep /$re/, @_; } foo(q{qr|<$client>|}, '', '', ''); # ==> ('', '')