# Instead of >perl -w myscript.pl -some -command -line # you invoke it as >perl -w myscript.pl -some -command -line >output.xml #### BEGIN { my $outfile = 'output.xml'; close STDOUT; open STDOUT, ">", $outfile or die "Couldn't create '$outfile': $!"; }; #### # Instead of sub frobnitz { my ($input) = @_; if ($input =~ /foo/) { $input =~ s!foo!frobnitz!g; print $input; }; }; # write: sub frobnitz { my ($input) = @_; if ($input =~ /foo/) { $input =~ s!foo!frobnitz!g; return "$input" } else { return $input; }; }; # ... print frobnitz($in);