foreach $line (@arr) { if ( $line =~ m{\s+\d+:\s+\d+\s*:(\S+:\S+:D\n?)$}g ) { #do something } }