% steph@ape (/home/stephan/t2) % % ls -1 bag'cmds driver.pl more cmds % steph@ape (/home/stephan/t2) % % cat $'bag\'cmds' echo just another shell hacker echo just another perl hacker % steph@ape (/home/stephan/t2) % % cat 'more cmds' echo .done % steph@ape (/home/stephan/t2) % % cat driver.pl #!/bin/perl use strict; use warnings; $|++; use Data::Dumper; # make this line after the q op. valid shell my $main_cmd = q{ cat bag\'cmds "more cmds" | sh }; my @cmd = ( '/bin/ksh', '-c', $main_cmd ); print Dumper(\@cmd); print "\n./bin/sh -c '/bin/ksh -c ...'\n"; system(@cmd) == 0 or warn; print "\n.directly: at the mercy of your system shell\n ->"; system('echo $0') == 0 or warn; print "\n"; system($main_cmd) == 0 or warn; print "\n.generating script\n"; my $cmd_file = qq{temp$$.sh}; open my $outh, '>', $cmd_file or die; print $outh <<"EOSHELL"; $main_cmd EOSHELL system('cat', '-evnt', $cmd_file) == 0 or warn; system('/bin/ksh', $cmd_file) == 0 or warn; unlink $cmd_file; __END__ % steph@ape (/home/stephan/t2) % % perl driver.pl $VAR1 = [ '/bin/ksh', '-c', ' cat bag\\\'cmds "more cmds" | sh ' ]; ./bin/sh -c '/bin/ksh -c ...' just another shell hacker just another perl hacker .done .directly: at the mercy of your system shell ->sh just another shell hacker just another perl hacker .done .generating script 1 $ 2 cat bag\'cmds "more cmds" | sh$ 3 $ just another shell hacker just another perl hacker .done