... foreach(@_) { # skip if it doesn't start with either a space or backslash next if (!/^[ \\]/); # skip if it's just "." or ".." next if (/^\s*\.{1,2}\s/); if (/^\\/) { $path = "$_\\" } elsif (/^\s*(.*\S)\s{5,}([HDRSA]+)\s*(\d+)\s*(.*)/) { my ($file,$att,$size,$date) = ($1,$2,$3,$4); my $ext = ( $file =~ /\.([^.]+)$/ ) ? $1 : "DIR"; print ...; } }