in reply to interpolate using backticks?
Course you might want to add some error checking. Maybe a regex to ensure that $dir is for real. You might get some odd results if $dir contained a pipe followed by an undesirable command. (hint... turn on taint checking)