The Devil is in the Details! Exactly what are you matching against, and exactly what do you want to match?
c:\@Work\Perl\monks>perl -wMstrict -le
"my $var = '%&!~ path_to_a_lib_of_my_lib';
;;
$var =~ m{ (.*) lib }xms;
print qq{A: '$1'};
;;
$var =~ m{ (.*?) lib }xms;
print qq{B: '$1'};
;;
$var =~ m{ (\w*?) lib }xms;
print qq{C: '$1'};
"
A: '%&!~ path_to_a_lib_of_my_'
B: '%&!~ path_to_a_'
C: 'path_to_a_'
Update: Please see perlre, perlretut, and perlrequick.
Further Update: If the string consists entirely in something like 'path_to_a_lib_of_my_lib', see also the start- and end-of-string "anchors" \A \z \Z (particularly \A \z in this case) for further narrowing what you want to capture.
Give a man a fish: <%-{-{-{-<
|