use File::Slurp qw; my $text = slurp("a5927574.txt"); my @items = split "ITEM ", $text; # print first item, as it is print shift @items; # prepend "ITEM " to the rest and print print "ITEM $_" for @items;