in reply to Parse $ Variable in text file

If you are willing to change the syntax of your txt file to
select * from emp where emp={$name}; select * from sal where code={$code};

Text::Template should be able to do the job easily. Other template systems will work as well but they usually have yet other syntaxes.

In this specific case, it might be easier to just use $dbh->selectall_hashref(eval $line); if you can trust the input of the textfile and the values in the variables.