use strict; use warnings; use File::Spec::Functions qw(:ALL); use feature 'say'; my $testpath = catdir('foo','bar'); #say $testpath; my ($sepchar) = $testpath =~ m/^foo(.+)bar$/ or die 'Separation character identification failed'; say $sepchar;