my $file = "somename.out"; my $name = ( split( /\./, $file ) )[0]; print "$file - $name\n"; # This prints "somename" correctly #### my $file_with_path = "path/somename.out" # or my $file_with_path2 = "path/path2/somename.out"