#! /usr/bin/perl use strict; while (my $line = ) { chomp $line; my @line = split ";", $line; next if $line[0] eq $line[1]; next unless length $line[0] == length $line[1]; my @one = breakup($line[0]); my @two = breakup($line[1]); next unless scalar(@one) == scalar(@two); my @match = map { $one[$_] eq ++$two[$_] || ++$one[$_] eq --$two[$_] ? 1 : 0 } (0..$#one); print $line, "\n" if 1 == grep {$_} @match; } sub breakup { my @out; while ($_[0]) { $_[0] =~ s/^([a-zA-z]|[0-9]+)//; push @out, $1; } return @out; }