#!/usr/bin/env bash paste -s -d '' input.txt | perl -lne ' print "$1$4$2$3" while /(?<=(.).(.).{138})A(?=.{138}(.).(.))/g ' | grep -Ec '(SM|MS){2}'