[...] if ($text =~ /FATAL: Error while copying /) { my $dt = substr($text,0,20); my $me = index($text,' from '); my $ml = $me - 47; my $msg = substr($text,47,$ml); $me += 6; my $se = index($text,' to '); my $sl = $se - $me; my $source = substr($text,$me,$sl); my $sbs = $me + 2; my $sbl = $se - $sbs; my $sourcebis = q{\\\\ENCNRW0010}.substr($text,$sbs,$sbl); $se += 4; my $de = index($text,', error was:'); my $dl = $de - $se; my $destination = substr($text,$se,$dl); File::Copy::copy $source.$msg,$destination; push (@mail,$dt.$msg.' from '.$sourcebis.' to '.$destination."\n"); $text =~ s/FATAL: Error while copying /FATAL (Fixed): Error while copying /g; print $text."\n"; } [...] #### 2017-11-16 11:42:20 FATAL: Error while copying MX000017105279_2448299.1523788.IN.EDI from D:\EnecoEDIELArchive\B2B_ELEK\ to \\ENCNRW0012\EnecoData\EDIEL_IN\B2B_ELEK\, error was: 2017-11-16 11:42:21 FATAL: Error while copying MX000017105328_3626588.1523787.IN.EDI from D:\EnecoEDIELArchive\B2B_ELEK\ to \\ENCNRW0012\EnecoData\EDIEL_IN\B2B_ELEK\, error was: