in reply to Question about split

Others have shown you how to solve the problem without using split, but I thought it might be nice to show how to solve it with split. I have made a number of assumptions that may not be correct, but I wanted to show you how to do this, just for your reference. (I also used a core module, File::Basename, that is very useful.)

use File::Basename; my ($ext, $dash) = ('.bmp', '-'); # assumptions my $f = '453445-5.bmp'; my ($base, $copy) = split /$dash/, basename($f, $ext); print "$base$dash$copy$ext\n"