my @fh = (\*OUT1, \*OUT2, \*OUT3); if (m/^([012])/) { my $index = $1; my $fh = $fh[$index]; print $fh "$_\n"; }