use Compiler::Errors 'file.out'; # will append use Compiler::Errors '>file.out'; # will overwrite use Compiler::Errors '>>file.out'; # will append use Compiler::Errors '| program'; # will pipe use Compiler::Errors '>&=1'; # dup to fd #### package Compiler::Errors; sub import { shift; # caller my $file = @_ ? shift : "compiler.err"; # default to appending to the file $file = ">> $file" if $file !~ /^[>|]/; open __SAVEERR, ">&STDERR"; # copy STDERR open STDERR, $file; # redirect STDERR } INIT { open STDERR, ">&__SAVEERR"; # restore STDERR close __SAVEERR; } 1;