#!perl -w use strict; sub print_in_columns { my %s; # Push the input array into the hash to indicate which # columns are present @s{@_} = (); # Loop through the permitted values and either print # the value ( if it exists in the hash %s, or print # an empty column if it isn't print exists $s{$_} ? "$_\t" : "\t" for ('A'..'G'); print "\n"; } print_in_columns split // while ; __DATA__ ABC ADE AFG CDB