sub change_punch_process { my @numbers; @q = ("1a", "2b", "3c", "2k"); foreach ( @q ) { if (/^([0-9]+)/) { my $exists = 0; foreach (@numbers) { $exists = 1 if ($_ == $1) } if (!$exists) {push @numbers, $1;} } } print join(",",@numbers); } change_punch_process;