#!/usr/bin/perl use warnings; use strict; use Test::More; use Benchmark qw{ cmpthese }; my @input = split /\n/, << '__INPUT__'; 12-12 12-12-12 12-13-12-13 12-12-13-13 12-13-13-14 __INPUT__ sub lenno { my @back; my @i = @input; for (@i) { my %h; undef $h{$1} while s/(\d\d)//; push @back, join ("-", sort keys %h); } \@back } sub choro { my @back; my @i = @input; for (@i) { my %h; undef $h{$1} while m/(\d\d)/g; push @back, join ('-', sort keys %h); } \@back } is_deeply(lenno(), choro(), 'same'); done_testing(); cmpthese(-3, { lenno => 'lenno', choro => 'choro', });