use strict; use warnings; my $pair_name; while (<>) { $pair_name = join '\\', split; last; } my %hash; my %col_header; my %row_header; while (<>) { my @pair = split; $hash{$pair[0]}{$pair[1]} = $row_header{$pair[0]} = $col_header{$pair[1]} = 1; } my @col_header = sort numeric keys %col_header; my @row_header = sort numeric keys %row_header; printf "%10s" x (@col_header + 1), $pair_name, @col_header; print "\n"; for my $row ( @row_header ) { printf "%10s", "$row"; for my $col ( @col_header ) { printf "%10s", ( exists( $hash{$row}{$col} ) ? "1" : "0"); } print "\n"; } sub numeric { $a <=> $b; }