foreach $dswfile ( @workspacefiles ) { $pathtodsw = "$root$dswfile"; $pathtodsw =~ s/(.*)\\.+?\.dsw/$1/; # Then I open the file and read the relevant data. }