my $string = "/opt/pmg/ptt/book1_test"; my ($path, $name) = ($string =~ m~^(.+/book)(.*)$~); print $path; # /opt/pmg/ptt/book print $name; # 1_test