Perl script? What?
As far as your actual problem, there may be other ways to do it (I
don't remember), but the easiest solution is just to include the value
of your variable sid in your query. If your query is currently doing
this:
select a, b from mytable
then simply change it to this instead:
select a, b, :sid as sid from mytable