#!/usr/bin/perl -w use strict; my %blockname = ( e => '%s;', B => '; BEGIN { %s };', E => '; END { %s };', ); my @arg; while (@ARGV && (my ($switch, $rest) = $ARGV[0] =~ /^-(.)(.*)/)) { if ($rest eq '-') { # early exit if -- push @arg, @ARGV; last; } if ($switch !~ /[BEe]/) { push @arg, shift @ARGV; next; } shift (@ARGV); if (not length $rest) { if(@ARGV) { $rest = shift (@ARGV); } else { $! = 2; # emulate perl(1) die "No code specified for -$switch."; } } push @arg, -e => sprintf $blockname{$switch}, $rest; } exec { $^X } $^X, @arg;