# after you've fetched the row my $escapedCustno = jsescape($custno); ... print < fillCustomer('$escapedCustno', ... sub jsescape { my $str = shift; $str =~ s/("')/\\$1/g; $str; }