for( map{ s/\\*([^\\]+)\.avi\n/$1/; $_ } `cmd /c dir /s /b *.avi` ) { $inventory{$1} = $2 if /^(.*?)s\d{1,2}[xe]\d{1,2})/i); } # BROKEN OUT -- follow the numbers for( map{ s/\\*([^\\]+)\.avi\n/$1/; # 2: isolate filename between last # backslash (if any) and newline $_ } # 3: pass on $_, not result of s///, which is the # number of replacements made `cmd /c dir /s /b *.avi` # 1: get avi files, including sub-dirs. # dir is a shell (cmd) command, so # you might need to call it this way. ) { $inventory{$1} = $2 if /^(.*?)s\d{1,2}[xe]\d{1,2})/i); }