#!/usr/bin/perl use strict; use warnings; map { print if s/\A (\w;\d) (?!;\d) / $1; /xms } ; __DATA__ a;3 b;2;3 c;5;4 d;6 #### Output : a;3; d;6;