my $string = "/opt/pmg/ptt/book1_test"; my $path_incl_book; if ( $string =~ / (.* book) /x ) { $path_incl_book = $1; }