in reply to $1 and regex

Maybe you should try ".*?", the fewest possible anythings:
while (<>) { / (\d+) .*? to .*? (\d+) /x and print "$1\n$2\n"; }