#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11136164 use warnings; my @data = map [ /\S+(?: \(\S+)?/g ], ; my @wide; for my $line ( @data ) { $wide[$_] |= '' . $line->[$_] for 0 .. $#$line; } $_ = sprintf "%%-%ds", length for @wide; my $format = join(' ', @wide) . "\n"; #printf $format, @$_ for @data; # previous code my $table = join '', map { sprintf $format, @$_ } @data; # new combine code print $table;