my ($key,$value); # DEBUG - BEGIN # your original regex $key= $line =~/;(.*)\s-\s/; $value= $line =~/\.\\(.*)-\d+\;/; print STDERR "key=<$key> value=<$value>\n"; #outputs: key=<1> value=<1> # the right way to get the value of the matched string in a # one liner - the parenthesis around ($key) and ($value) tell # perl that you want to return the array of matches, NOT the # number of matches. ($key) = $line =~/;(.*)\s-\s/; ($value) = $line =~/\.\\(.*)-\d+\;/; print STDERR "key=<$key> value=<$value>\n"; # outputs: key= value=<\root\edit\perl\scripts\scripths\sec\inc\script_auth_pap.h> # The above still doesn't work because your key will include all # file names after the first ";" before " - " and not just the one # between the last ";" and " - ". To get only the last one you need # a more restrictive regex, one that insures that there # are no ";" in your key, e.g. ([^;]*). You also proabably # want to have a key with at least one character, so you should use # ([^;]+) rather than ([^;]*). ($key) = $line =~/;([^;]+)\s-\s/; ($value) = $line =~/\.\\(.*)-\d+\;/; # see comment below for why this is printed out to # STDERR and is followed by "last" print STDERR "key=<$key> value=<$value>\n"; last; # DEBUG - END