#!/usr/bin/perl my $string="realllylongstringthatrefusestoend". " \n"; print splitter($string,"<.*?>","\S{18}","$1 "); sub splitter{ my($string,$spliton,$find,$replace)=@_; my @array=split(/$spliton/,$string); my $i=0; my @splitters; my $str; while($string=~/($spliton)/g){ push @splitters,$1; } for(@array){ #none of these work #s/$find/$replace/eeg; #s/$find/$1 /g; #eval '$string' . " =~ s/$find/$replace/"; #this works s/(\S{18})/$1 /g; $str.=$array[$i]; $str.=$splitters[$i]; $i++; } $str; }