in reply to STDERR, preserve order of

This might be more of an off-the-wall approach (but I can't think of the right way to capture STDERR at the moment, so ...) but why not split the filename/dirname component out of the ls listing and use that as the key in a hash of hash refs and do the same with the output from the lsattr command?

This is a very crude first approximation, but the output should give you some ideas. Any key that doesn't have an attr element can be presumed to have had STDERR output that you weren't using.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; my @list = `ls -lU`; my @chattr = `lsattr`; my %combined; foreach my $attritem (@chattr) { chomp $attritem; my @attrdata = split(' ',$attritem); my $attritemname = pop(@attrdata); $attritemname =~ s{^\./}{}; $combined{$attritemname}{attr} = join(' ',@attrdata); } foreach my $item (@list) { chomp $item; my @lsdata = split(' ',$item); my $itemname = pop(@lsdata); $combined{$itemname}{ls} = join(' ',@lsdata); } print Dumper(\%combined); exit; __END__ $VAR1 = { 'fortest.pl' => { 'ls' => '-rwx------ 1 user group 547 Jun 26 22:57', 'attr' => '---------------' }, 'lsattrtest.pl' => { 'ls' => '-rwx------ 1 user group 587 Sep 9 23:10', 'attr' => '---------------' }, 'inctest.pl' => { 'ls' => '-rwx------ 1 user group 75 Aug 5 2012', 'attr' => '---------------' }, }, 'fiscaltest.pl' => { 'ls' => '-rwx------ 1 user group 247 Jul 17 15:34', 'attr' => '---------------' }, 'moosetest.pl' => { 'ls' => '-rwx------ 1 user group 72 Aug 15 00:53', 'attr' => '---------------' }, 'str2dt.pl' => { 'ls' => '-rwx------ 1 user group Jul 17 15:28', 'attr' => '---------------' } };

UPDATE: corrected typo, added sample output.