#!/usr/bin/perl use strict; use warnings; use feature 'say'; my $text='abc 1foo 1x1 ee2 3B4 n 5 6t7 q9q 5+6'; while ($text=~/(\d)([[:alpha:]])(\d)/g) { if ($1 + 1 == $3) { say "$1$2$3 is wanted because $1 + 1 = $3"; } else { say "$1$2$3 matches, but is not wanted ($1 + 1 != $3)"; } }