use strict; my @files = ("08","09"); for my $file (@files) { my @command = `ls -l|grep $file`; print "$file $#command\n"; }