Have you tried to profile and see where is the time spent? You don't have $PREMATCH $`, $MATCH $& or $POSTMATCH $' anywhere in your code, do you? (See perldoc perlvar) Gabor