One of my favourite old-school Perl magic spells used to portably handle broken shells is:
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0;
See: https://www.perl.com/article/bang-bang/