foreach (@files) { open FILE, "$_" or die $!; print "$_", br() x3; $_ = map m{([^/]+)\.txt}, $_; #Strip out of the string the path and extension leaving only the filename intact ... }