Would not the more "elegant" solution be to use a module that is designed for this purpose, File::Spec? From the documentation for the module, File::Spec requires an appropriate module (File::Spec::Cygwin, File::Spec::Unix, and File::Spec::Win32, among others), which alters such functions as catfile in an appropriate manner. Taking from ww's example (and setting the path value in a sub) using this code:
perl -MFile::Spec -le 'sub tshark_path { my @filename = qw( / usr bin
+tshark ); if ( $^O eq q{MSWin32} ) { @filename = ( q{c:}, q{Program F
+iles}, q{Wireshark}, q{tshark.exe} ); } return @filename; } my @file
+= tshark_path(); print File::Spec->catfile( @file );'
gives the following results when executed on Cygwin (under Win10), Win10, and linux:
# Result under Cygwin
/usr/bin/tshark
# Result under Win10 (Powershell)
C:\Program Files\Wireshark\tshark.exe
# Result from linux
/usr/bin/tshark
Hope that helps.