#!/usr/bin/perl use strict; use warnings; use File::Temp qw/tempdir tempfile/; use File::Copy; open my $f,'<','./test' or die "$!"; my $content = do { local($/); <$f>; }; my $temp_dir = '/home/mkurz/tmp'; my ($fh,$filename) = create_temp_file($temp_dir); print $fh $content; move_files($filename, $temp_dir); sub move_files { my ($file1, $temp_dir) = @_; my $dir = create_temp_dir($temp_dir); print $dir; copy("$file1","$dir"); } sub create_temp_dir { my($temp_dir) = @_; my $dir = tempdir( CLEANUP => '0', DIR => "$temp_dir", ); return $dir; } sub create_temp_file { my ($temp_dir) = @_; my ($dir, $fh, $filename); $dir = tempdir( CLEANUP => '1', DIR => "$temp_dir", ); ($fh, $filename) = tempfile( DIR => $dir, SUFFIX => '.idoc', ); # binmode( $fh, ":utf8" ); return $fh, $filename; }