# single quotes prevent interpolation my $sed_command = 'sed -e :a -e "$d;N;2,3ba" -e "P;D" /db2/$DB2DBDFT/Messages/temp.txt'; my $result = `$sed_command`; # passes a literal $d to sed, not the contents of the $d perl variable.