use Getopt::Long; sub option_replacement { my( $spec, $func ) = @_; local $Getopt::Long::passthrough=1; my @newARGV; GetOptions( $spec => sub { push @newARGV, &$func }, '<>' => sub { push @newARGV, @_ }, ); @ARGV = @newARGV; }