#!/usr/bin/perl -w use strict; my %filehandles; foreach ('call1','call2') { open my $fh, '>>', $_ or die "can't open $_ for append $!"; $filehandles{$_}=$fh; } # use call_id in the print to select the right filehandle to # write to my $call_id = "call1"; print {$filehandles{$call_id}} "to file1\n"; $call_id = "call2"; print {$filehandles{$call_id}} "to file2\n";