my $re_a = qr/a/; my $re_b = qr/b/; sub f { my $re = $_[0]; (my $str = 'abba') =~ s/$re//g; } f($re_a); f($re_b); f($re_a); f($re_b);