#!/usr/bin/perl -w use strict; $|++; sub do_something(*@) { local *HANDLE = shift; print HANDLE @_; } # set up filehandles for this example # you'll probably use open()... local *B = *STDOUT; local *T = *STDERR; my %map_char_to_handle = ( B => *B, T => *T, # etc. ); while() { my $test_for_handle = substr($_, 2, 1); defined $map_char_to_handle{$test_for_handle} and do_something($map_char_to_handle{$test_for_handle}, $_); } __DATA__ ABC123 CAB234 BTT456 BXC789