#!/usr/bin/perl -w use strict; my $line="One two three four five"; my @chunks; if(@chunks = $line =~ m/(one)\s(two)\s(three)\s(four)\s(five)/i){ $chunks[0] =~ s/One/ONE/; # Change the first chunk $chunks[1] =~ s/two/tWo/; # Change the second chunk # ... } print "@chunks\n"; #### ONE tWo three four five