#! /usr/bin/perl my %stem; while( <> ) { chomp; next unless /^(.*)(?:m|rn)$/; print "${1}m -vs- ${1}rn\n" if ++$stem{$1} == 2; }