use strict; use warnings; my ($fh, $cmd); my $cmdI=0; open($fh, '>', 'log.txt'); while(1){ print ++$cmdI."> "; $cmd = || exit; print $fh $cmd; chomp($cmd); # this way you pass your command via the default shell with all the interpolations happening #system($cmd) && die "failed to run command: $cmd"; # this way you avoid the default shell and launch your perl script directly but # the command line is just one huge parameter (it does not break on whitespace, like a shell would do) $cmd=~ s/^mycommand\.pl// || die "$0 : your command must always be 'mycommand.pl'\n"; system('mycommand.pl', $cmd); }