#!/usr/bin/perl use warnings; use strict; my $txt = 'test'; my $foo = 'foo'; my $fix = 'bar'; $txt =~ s/test/$foo$fix/; print "$txt\n";