#!/usr/bin/perl # https://perlmonks.org/?node_id=1218823 use strict; use warnings; my %dups; local $_ = do { local $/; }; /\b(\d+)\b.*?\b(\d+)\b(?{$dups{"$1 $2"}++})(*FAIL)/; $dups{$_} > 1 and print "$_ repeated $dups{$_} times\n" for sort keys %dups; __DATA__ 1 2 5 9 1 2 5 10 4 5 10 12 5 9 10 11 #### 1 2 repeated 2 times 1 5 repeated 2 times 2 5 repeated 2 times 5 10 repeated 3 times 5 9 repeated 2 times