#! perl use strict; use warnings; # read data sequence from user my $data = "TGCAACTGCATACGTACTCGACTGCATT"; # read separator from user my $separator = "TG"; # split sequence into parts my @splitted = do { # open filehandle for input data; maybe a filename later? open( my $fh, '<', \$data ) or die "Could not open data."; # set input field separator (it is NOT removed from the resulting parts) local $/ = $separator; # read parts from filehandle (list context because of @splitted) <$fh>; }; # control; print each part in @splitted per line print join "\n", @splitted, "";