use Text::Diff; my $diff = diff ("test.txt", "test2.txt", { OUTPUT => sub { my $item = shift; if ($item =~ m{^(\+|-)/}) { push @output, $item } } } );