while ( my $line = ) { my @words = split /,/, $line; foreach my $word ( @words ) { $word =~ s/_/ /g; print "ID: $word\n"; } }