use strict; use warnings; my $regex = qr| Primary\s\(Reporting\)\s Cp\s*:\s*((?:(?!Set).)*) # Now we can see what's happening Set\s*:\s*((?:(?!Car).)*) # but why are the look aheads needed? Car\s*:\s*((?:(?!Ref).)*) |six; while () { next if $_ !~ $regex; print; } #### __DATA__ ==================================================================== Record: 9851329 Version: 2 Timestamp: Sat Feb 11 22:39:43 2006 Primary (Reporting) Cp: 113 Set: 2 Car: 1 Ref: yes Event: 9922 Missing P: Keep: 1 Phase: 0x2fdf Strength: 24 Secondary Sector Information: ==================================================================== Record: 9851330 Version: 2 Timestamp: Sat Feb 11 22:39:43 2006 Primary (Reporting) Cp: 115 Set: 1 Car: 2 Ref: yes Event: 9923 Missing P: Keep: 1 Phase: 0x7d10 Strength: 31 Secondary Sector Information: Slot 1: Keep: 1 offset: 391 Strength: 27 Ref: no Slot 2: Keep: 1 offset: 325 Strength: 38 Ref: no #### Primary (Reporting) Cp: 113 Set: 2 Car: 1 Ref: yes Event: 9922 Primary (Reporting) Cp: 115 Set: 1 Car: 2 Ref: yes Event: 9923