my $string = "Hello sailor"; my $regex = qr/Hello (.*)/; $string =~ s/$regex/Goodbye \1/; print "string is now $string \n";