for (glob "*.txt") { my $lsoutput = qx(ls -l $_); if ($lsoutput =~ /$ENV{USER}/) { print "File matches current username.\n"; } } #### for (glob "*.txt") { open my $lsfh, "-|", 'ls', '-l', $_ or die "Cannot open 'ls': $!\n"; while (<$lsfh>) { if ($lsoutput =~ /$ENV{USER}/) { print "File matches current username.\n"; } } }