Question is how to write a regular expression which can do backreferencing so that so that 3 lines can backreerenced at once.. For example: [0-100] to match this one could write (\[[0-9]+\-[0-9]+\]) and once the string is matched it can be extracted in using $var=$1 which should get [0-100] Now how could one write Regular expression to extract 3 lines as given in problem description..