use File::Spec; #... my $name=File::Spec->splitpath( $file ); $name=~s/_.+?$//;