Here's the simple solution.
#!/usr/bin perl -w print "Script started\n"; eval { exec("perl -wT $0") #Only works if taint mode off }; print "Now we're in taint mode!\n";
Unfortunately, if your script is suid, this has a gaping security hole, as you've just executed an arbitrary program as root. (Was it /usr/bin/perl as you were expecting, or was it /home/l33t_hax0r/bin/perl? With an insecure $ENV{PATH}, you'll never know.)

Here's a version that fixes that particular hole

#!/usr/bin perl -w print "Script started\n"; eval { $ENV{PATH}, exec("/path/to/perl -wT $0") #Only works if ta +int mode off }; print "Now we're in taint mode!\n";
Eliminating the "useless use of a hash element in void context" message is left as an exercise for the reader. (Hint: look at the is_tainted function example in perlsec)

--
Ryan Koppenhaver, Aspiring Perl Hacker
"I ask for so little. Just fear me, love me, do as I say and I will be your slave."


In reply to Re: perl -T script.pl and #!/usr/bin/perl -T conflict by rlk
in thread perl -T script.pl and #!/usr/bin/perl -T conflict by ichimunki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.