use strict; use Carp; use IO::File; my @handles; push @handles, IO::File->open(">c:/File1.txt") || die "Can't open File1 for writing\n"; push @handles, IO::File->open(">c:/File2.txt") || die "Can't open File2 for writing\n"; for my $variable ( 0..1 ) { # write this to both files print { $handles[$variable] } "Hello\n"; }