my $re = /\d+$/; # for an example pattern $thingy =~ /My Zip code is $re/; $thingy =~ /$re/; $thingy =~ s/foo{$re}bar/baz/; etc...