#!/usr/bin/env perl5.22.1 use strict; use warnings; use 5.10.1; my $x ="aaa bbb ccc dd ee ff dd TAG=lls foo TAG=some randome tag TAG=last_tag"; #my $x ="TAG=lls foo TAG=some randome tag TAG=last_tag"; my @tags = split /\s*TAG=/, $x; # before the first TAG, discard. shift @tags; my $i = 0; say "tag ", $i++, ": [$_]" for @tags;