Using a module and a regex:
use Modern::Perl qw/2015/;
use File::Spec;
while ( my $fullfile = <DATA> ) {
chomp $fullfile;
my ( $volume, $directories, $file ) = File::Spec->splitpath($fullf
+ile);
$file =~ /^([^.]+).*(\.[^.]+)/;
say File::Spec->catpath( $volume, $directories, "$1$2" );
}
__DATA__
9781437706734\BODY\B978143770673410006X\B978143770673410006X.xml1.xml.
+xml
9781437706734\BODY\B9781437706734100010\B9781437706734100010.xml1.xml.
+xml
9781437706734\REAR\B9781437706734102000\B9781437706734102000.xml1.xml.
+xml
9781437706734\REAR\B9781437706734102050\B9781437706734102050.xml1.xml.
+xml
9781437706734\REAR\B9781437706734102051\B9781437706734102051.xml1.xml.
+xml
a\funny\file\path\with_too_many.file.extensions.in.the.file.name.txt
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog:
Imperial Deltronics